---
title: "ANES Attitude Stablity"
output: html_document
---
#Load Data Sets
```{r}
library(rio)
library(stats)
library(dplyr)
library(wCorr)
library(survey)
library(weights)
library(scales)
library(ggpubr)

anes04=import("anes2004TS.dta")
anes08=import("anes_timeseries_2008.dta")
anes12=import("anes_timeseries_2012.dta")
anes16=import("anes_timeseries_2016.dta")
anes20=import("anes_timeseries_2020_csv_20220210.csv")
```

#Dependent Variables
2004 Dependent Variables: Traditional values and Modern Sexism
```{r}
#####Traditional Family roles (TFR) (additive index)

#TFR1: more traditional family ties
table(anes04$V045192)
anes04$morefamilyties=ifelse(anes04$V045192==1,5,
                        ifelse(anes04$V045192==2,4,
                               ifelse(anes04$V045192==3,3,
                                      ifelse(anes04$V045192==4,2,
                                             ifelse(anes04$V045192==5,1,NA)))))
table(anes04$morefamilyties)


#TFR 2: Easier or harder for a mom working outside the home to bond with her kids 
table(anes04$V045205)
anes04$working_mother_bond=ifelse(anes04$V045205==5,3,
                               ifelse(anes04$V045205==3,2,  
                                      ifelse(anes04$V045205==1,1,NA)))
table(anes04$working_mother_bond)
cor(anes04$morefamilyties, anes04$working_mother_bond, use = "complete.obs") #Checks out



#TFR 3:Better for man to work outside the home while while wife takes care of home and family
table(anes04$V045206)
anes04$fatherwork_mother_home=ifelse(anes04$V045206==1,3,
                               ifelse(anes04$V045206==3,2,  
                                      ifelse(anes04$V045206==5,1,NA)))
table(anes04$fatherwork_mother_home)
cor(anes04$morefamilyties, anes04$fatherwork_mother_home, use = "complete.obs") #Checks out
cor(anes04$working_mother_bond, anes04$fatherwork_mother_home, use = "complete.obs") #Checks out

library(ltm)
ca=anes04[,c("morefamilyties","working_mother_bond","fatherwork_mother_home")]
cronbach.alpha(ca,na.rm = T) #.512

anes04$traditional_values_index=anes04$morefamilyties+anes04$working_mother_bond+anes04$fatherwork_mother_home
table(anes04$traditional_values_index)  
  
table(is.na(anes04$traditional_values_index))

####Modern Sexism Traditiona (MS) (additive index)


#MS 1: Favors
table(anes04$V045183)
anes04$speacialfavors_women=ifelse(anes04$V045183 ==1,5,
                                   ifelse(anes04$V045183 ==2,4,
                                          ifelse(anes04$V045183 ==3,3,
                                                 ifelse(anes04$V045183 ==4,2,
                                                        ifelse(anes04$V045183 ==5,1,NA)))))
table(anes04$speacialfavors_women)
                             

#MS 2: Complaining creates more problems
table(anes04$V045185)
anes04$women_complaints_make_more_problems=ifelse(anes04$V045185 ==1,5,
                                                  ifelse(anes04$V045185 ==2,4,
                                                         ifelse(anes04$V045185 ==3,3,
                                                                ifelse(anes04$V045185 ==4,2,
                                                                       ifelse(anes04$V045185 ==5,1,NA)))))
table(anes04$women_complaints_make_more_problems)
cor(anes04$speacialfavors_women, anes04$women_complaints_make_more_problems, use = "complete.obs") #Checks out





library(ltm)
ca=anes04[,c("speacialfavors_women","women_complaints_make_more_problems")]
cronbach.alpha(ca,na.rm = T) #.608
anes04$modern_sexism_index=anes04$speacialfavors_women+anes04$women_complaints_make_more_problems

#Rescale Variables
anes04$traditional_values_index=rescale(anes04$traditional_values_index) 
anes04$modern_sexism_index=rescale(anes04$modern_sexism_index) 

```

2008 Dependent Variables: Traditional values and Modern Sexism
```{r}
#####Traditional Family roles (TFR) (additive index)

#TFR1: more traditional family ties
table(anes08$V085142)
anes08$morefamilyties=ifelse(anes08$V085142==1,5,
                        ifelse(anes08$V085142==2,4,
                               ifelse(anes08$V085142==3,3,
                                      ifelse(anes08$V085142==4,2,
                                             ifelse(anes08$V085142==5,1,NA)))))
table(anes08$morefamilyties)


#TFR 2: Easier or harder for a mom working outside the home to bond with her kids. Slightly Different wording and fewer answer options than in later surveys

table(anes08$V085155)
anes08$working_mother_bond=ifelse(anes08$V085155 == 5,3,
                                  ifelse(anes08$V085155 == 3,2,
                                         ifelse(anes08$V085155 == 1,1,NA)))
                                  
                                  
table(anes08$working_mother_bond)
cor(anes08$morefamilyties, anes08$working_mother_bond, use = "complete.obs") #Checks out

#TFR 3:Better for man to workoutside the home while while wife takes care of home and family
table(anes08$V085156)
anes08$fatherwork_mother_home=ifelse(anes08$V085156==1,3,
                                     ifelse(anes08$V085156==3,2,
                                            ifelse(anes08$V085156==5,1,NA)))
                                     
table(anes08$fatherwork_mother_home)
cor(anes08$morefamilyties, anes08$fatherwork_mother_home, use = "complete.obs") #Checks out
cor(anes08$working_mother_bond, anes08$fatherwork_mother_home, use = "complete.obs") #Checks out

library(ltm)
ca=anes08[,c("morefamilyties","working_mother_bond","fatherwork_mother_home")]
cronbach.alpha(ca,na.rm = T) #0.411

anes08$traditional_values_index=anes08$morefamilyties+anes08$working_mother_bond+anes08$fatherwork_mother_home
table(anes08$traditional_values_index)  
  
table(is.na(anes08$traditional_values_index))
####Modern Sexism Traditiona (MS) (additive index)


#MS 1: Favors
table(anes08$V085136)
anes08$speacialfavors_women=ifelse(anes08$V085136 ==1,5,
                                   ifelse(anes08$V085136 ==2,4,
                                          ifelse(anes08$V085136 ==3,3,
                                                 ifelse(anes08$V085136 ==4,2,
                                                        ifelse(anes08$V085136 ==5,1,NA)))))
table(anes08$speacialfavors_women)
                             


#MS 2: Complaining creates more problems
table(anes08$V085138)
anes08$women_complaints_make_more_problems=ifelse(anes08$V085138 ==1,5,
                                                  ifelse(anes08$V085138 ==2,4,
                                                         ifelse(anes08$V085138 ==3,3,
                                                                ifelse(anes08$V085138 ==4,2,
                                                                       ifelse(anes08$V085138 ==5,1,NA)))))
cor(anes08$speacialfavors_women, anes08$women_complaints_make_more_problems, use = "complete.obs") #Checks out


library(ltm)
ca=anes08[,c("speacialfavors_women","women_complaints_make_more_problems")]
cronbach.alpha(ca,na.rm = T) #0.578
anes08$modern_sexism_index=anes08$speacialfavors_women+anes08$women_complaints_make_more_problems

summary(anes08$modern_sexism_index)

#Rescale Variables
anes08$traditional_values_index=rescale(anes08$traditional_values_index) 
anes08$modern_sexism_index=rescale(anes08$modern_sexism_index)
```

2012 Dependent Variables: Traditional values and Modern Sexism
```{r}
#####Traditional Family roles (TFR) (additive index)

#TFR1: more traditional family ties
table(anes12$trad_famval)
anes12$morefamilyties=ifelse(anes12$trad_famval==1,5,
                        ifelse(anes12$trad_famval==2,4,
                               ifelse(anes12$trad_famval==3,3,
                                      ifelse(anes12$trad_famval==4,2,
                                             ifelse(anes12$trad_famval==5,1,NA)))))
table(anes12$morefamilyties)


#TFR 2: Easier or harder for a mom working outside the home to bond with her kids 
table(anes12$women_bond_x)
anes12$working_mother_bond=ifelse(anes12$women_bond_x <0,NA,anes12$women_bond_x)
table(anes12$working_mother_bond)
cor(anes12$morefamilyties, anes12$working_mother_bond, use = "complete.obs") #Checks out

#TFR 3:Better for man to workoutside the home while while wife takes care of home and family
table(anes12$women_works_x)
anes12$fatherwork_mother_home=ifelse(anes12$women_works_x==1,7,
                                ifelse(anes12$women_works_x==2,6,   
                                    ifelse(anes12$women_works_x==3,5,
                                           ifelse(anes12$women_works_x==4,4,
                                                  ifelse(anes12$women_works_x==5,3,
                                                         ifelse(anes12$women_works_x==6,2,
                                                                ifelse(anes12$women_works_x==7,1,NA)))))))
table(anes12$fatherwork_mother_home)
cor(anes12$morefamilyties, anes12$fatherwork_mother_home, use = "complete.obs") #Checks out
cor(anes12$working_mother_bond, anes12$fatherwork_mother_home, use = "complete.obs") #Checks out

library(ltm)
ca=anes12[,c("morefamilyties","working_mother_bond","fatherwork_mother_home")]
cronbach.alpha(ca,na.rm = T) #0.524

anes12$traditional_values_index=anes12$morefamilyties+anes12$working_mother_bond+anes12$fatherwork_mother_home
table(anes12$traditional_values_index)  
  
table(is.na(anes12$traditional_values_index))
 

####Modern Sexism Traditiona (MS) (additive index)


#MS 1: Favors
table(anes12$modsex_special)
anes12$speacialfavors_women=ifelse(anes12$modsex_special < 0, NA, anes12$modsex_special)
table(anes12$speacialfavors_women)
                             


#MS 2: Complaining creates more problems
table(anes12$modsex_prob)
anes12$women_complaints_make_more_problems=ifelse(anes12$modsex_prob <0, NA, anes12$modsex_prob)
cor(anes12$speacialfavors_women, anes12$women_complaints_make_more_problems, use = "complete.obs") #Checks out

#MS 3: Media should pay more attnetion to discrimination against women
table(anes12$modsex_media_x)
anes12$media_gender_disrimination_attention=ifelse(anes12$modsex_media_x <0,NA,anes12$modsex_media_x)

cor(anes12$media_gender_disrimination_attention, anes12$speacialfavors_women, use = "complete.obs") #Checks out
cor(anes12$media_gender_disrimination_attention, anes12$women_complaints_make_more_problems, use = "complete.obs") #Checks out



library(ltm)
ca=anes12[,c("speacialfavors_women","women_complaints_make_more_problems","media_gender_disrimination_attention")]
cronbach.alpha(ca,na.rm = T) #0.469

anes12$modern_sexism_index=anes12$speacialfavors_women+anes12$women_complaints_make_more_problems

anes12$modern_sexism_indexv2=anes12$speacialfavors_women+anes12$women_complaints_make_more_problems+anes12$media_gender_disrimination_attention


table(is.na(anes12$modern_sexism_index))

#Rescale Variables
anes12$traditional_values_index=rescale(anes12$traditional_values_index) 
anes12$modern_sexism_index=rescale(anes12$modern_sexism_index)
```

2016 Dependent Variables: Traditional values and Modern Sexism
```{r}
#####Traditional Family roles (TFR) (additive index)

#TFR1: more traditional family ties
table(anes16$V162210)
anes16$morefamilyties=ifelse(anes16$V162210==1,5,
                        ifelse(anes16$V162210==2,4,
                               ifelse(anes16$V162210==3,3,
                                      ifelse(anes16$V162210==4,2,
                                             ifelse(anes16$V162210==5,1,NA)))))
table(anes16$morefamilyties)


#TFR 2: Easier or harder for a mom working outside the home to bond with her kids 
table(anes16$V162229x)
anes16$working_mother_bond=ifelse(anes16$V162229x <0,NA,anes16$V162229x)
table(anes16$working_mother_bond)
cor(anes16$morefamilyties, anes16$working_mother_bond, use = "complete.obs") #Checks out

#TFR 3:Better for man to workoutside the home while while wife takes care of home and family
table(anes16$V162230x)
anes16$fatherwork_mother_home=ifelse(anes16$V162230x==1,7,
                                ifelse(anes16$V162230x==2,6,   
                                    ifelse(anes16$V162230x==3,5,
                                           ifelse(anes16$V162230x==4,4,
                                                  ifelse(anes16$V162230x==5,3,
                                                         ifelse(anes16$V162230x==6,2,
                                                                ifelse(anes16$V162230x==7,1,NA)))))))
table(anes16$fatherwork_mother_home)
cor(anes16$morefamilyties, anes16$fatherwork_mother_home, use = "complete.obs") #Checks out
cor(anes16$working_mother_bond, anes16$fatherwork_mother_home, use = "complete.obs") #Checks out

library(ltm)
ca=anes16[,c("morefamilyties","working_mother_bond","fatherwork_mother_home")]
cronbach.alpha(ca,na.rm = T) #0.527

anes16$traditional_values_index=anes16$morefamilyties+anes16$working_mother_bond+anes16$fatherwork_mother_home
table(anes16$traditional_values_index)  
  
table(is.na(anes16$traditional_values_index))
####Modern Sexism Traditiona (MS) (additive index)


#MS 1: Favors
table(anes16$V162232)
anes16$speacialfavors_women=ifelse(anes16$V162232==1,5,
                                   ifelse(anes16$V162232==2,4,
                                          ifelse(anes16$V162232==3,3,
                                                 ifelse(anes16$V162232==4,2,
                                                        ifelse(anes16$V162232==5,1,NA)))))
#MS 2: Complaining creates more problems
table(anes16$V162233)
anes16$women_complaints_make_more_problems=ifelse(anes16$V162233==1,5,
                                   ifelse(anes16$V162233==2,4,
                                          ifelse(anes16$V162233==3,3,
                                                 ifelse(anes16$V162233==4,2,
                                                        ifelse(anes16$V162233==5,1,NA)))))
cor(anes16$speacialfavors_women, anes16$women_complaints_make_more_problems, use = "complete.obs") #Checks out



#MS 3: Media should pay more attnetion to discrimination against women
table(anes16$V162231x)
anes16$media_gender_disrimination_attention=ifelse(anes16$V162231x <0,NA,anes16$V162231x)
table(anes16$media_gender_disrimination_attention)

cor(anes16$media_gender_disrimination_attention, anes16$speacialfavors_women, use = "complete.obs") #Checks out
cor(anes16$media_gender_disrimination_attention, anes16$women_complaints_make_more_problems, use = "complete.obs") #Checks out

library(ltm)
ca=anes16[,c("speacialfavors_women","women_complaints_make_more_problems","media_gender_disrimination_attention")]
cronbach.alpha(ca,na.rm = T) #0.627

anes16$modern_sexism_index=anes16$speacialfavors_women+anes16$women_complaints_make_more_problems+anes16$media_gender_disrimination_attention

anes16$modern_sexism_indexv2=anes16$speacialfavors_women+anes16$women_complaints_make_more_problems


#Rescale Variables
anes16$traditional_values_index=rescale(anes16$traditional_values_index) 
anes16$modern_sexism_index=rescale(anes16$modern_sexism_index)
```

2020 Dependent Variables: Traditional values and Modern Sexism
```{r}
#####Traditional Family roles (TFR) (additive index)

#TFR1: more traditional family ties
table(anes20$V202265)
anes20$morefamilyties=ifelse(anes20$V202265==1,5,
                        ifelse(anes20$V202265==2,4,
                               ifelse(anes20$V202265==3,3,
                                      ifelse(anes20$V202265==4,2,
                                             ifelse(anes20$V202265==5,1,NA)))))
table(anes20$morefamilyties)


#TFR 2: Easier or harder for a mom working outside the home to bond with her kids 
table(anes20$V202286x)
anes20$working_mother_bond=ifelse(anes20$V202286x <0,NA,anes20$V202286x)
table(anes20$working_mother_bond)
cor(anes20$morefamilyties, anes20$working_mother_bond, use = "complete.obs") #Checks out

#TFR 3:Better for man to workoutside the home while while wife takes care of home and family
table(anes20$V202290x)
anes20$fatherwork_mother_home=ifelse(anes20$V202290x==1,7,
                                ifelse(anes20$V202290x==2,6,   
                                    ifelse(anes20$V202290x==3,5,
                                           ifelse(anes20$V202290x==4,4,
                                                  ifelse(anes20$V202290x==5,3,
                                                         ifelse(anes20$V202290x==6,2,
                                                                ifelse(anes20$V202290x==7,1,NA)))))))
table(anes20$fatherwork_mother_home)
cor(anes20$morefamilyties, anes20$fatherwork_mother_home, use = "complete.obs") #Checks out
cor(anes20$working_mother_bond, anes20$fatherwork_mother_home, use = "complete.obs") #Checks out

library(ltm)
ca=anes20[,c("morefamilyties","working_mother_bond","fatherwork_mother_home")]
cronbach.alpha(ca,na.rm = T) #0.536

anes20$traditional_values_index=anes20$morefamilyties+anes20$working_mother_bond+anes20$fatherwork_mother_home
table(anes20$traditional_values_index)  
  
table(is.na(anes20$traditional_values_index))
####Modern Sexism Traditiona (MS) (additive index)


#MS 1: Favors
table(anes20$V202291)
anes20$speacialfavors_women=ifelse(anes20$V202291==1,5,
                                   ifelse(anes20$V202291==2,4,
                                          ifelse(anes20$V202291==3,3,
                                                 ifelse(anes20$V202291==4,2,
                                                        ifelse(anes20$V202291==5,1,NA)))))
#MS 2: Complaining creates more problems
table(anes20$V202292)
anes20$women_complaints_make_more_problems=ifelse(anes20$V202292==1,5,
                                   ifelse(anes20$V202292==2,4,
                                          ifelse(anes20$V202292==3,3,
                                                 ifelse(anes20$V202292==4,2,
                                                        ifelse(anes20$V202292==5,1,NA)))))
cor(anes20$speacialfavors_women, anes20$women_complaints_make_more_problems, use = "complete.obs") #0.6312812


library(ltm)
ca=anes20[,c("speacialfavors_women","women_complaints_make_more_problems")]
cronbach.alpha(ca,na.rm = T) #0.774
anes20$modern_sexism_index=anes20$speacialfavors_women+anes20$women_complaints_make_more_problems

#Rescale Variables
anes20$traditional_values_index=rescale(anes20$traditional_values_index) 
anes20$modern_sexism_index=rescale(anes20$modern_sexism_index)
```

Perceptions of Discrimination Against Women from all years
```{r}
#2004, slightly different question which asks about whether women miss out on jobs due to discrimination
table(anes04$V045184)
anes04$percieved_gender_discrimination=ifelse(anes04$V045184 >5,NA,anes04$V045184)
                                              
table(anes04$percieved_gender_discrimination)

#2008,slightly different question which asks about whether women miss out on jobs due to discrimination
table(anes08$V085137)
anes08$percieved_gender_discrimination=ifelse(anes08$V085137 <1,NA,anes08$V085137)
table(anes08$percieved_gender_discrimination)

#2012
table(anes12$modsex_discamt)
anes12$percieved_gender_discrimination=ifelse(anes12$modsex_discamt==5,1,
                                              ifelse(anes12$modsex_discamt==4,2,
                                                     ifelse(anes12$modsex_discamt==3,3,
                                                            ifelse(anes12$modsex_discamt==2,4,
                                                                   ifelse(anes12$modsex_discamt==1,5,NA)))))
table(anes12$percieved_gender_discrimination)

#2016
table(anes16$V162362)
anes16$percieved_gender_discrimination=ifelse(anes16$V162362 <0,NA, anes16$V162362)
table(anes16$percieved_gender_discrimination)

#2020
table(anes20$V202534)
anes20$percieved_gender_discrimination=ifelse(anes20$V202534  <0,NA,anes20$V202534)
table(anes20$percieved_gender_discrimination)


#Rescale Variables
anes04$percieved_gender_discrimination_rescaled=rescale(anes04$percieved_gender_discrimination) 
anes08$percieved_gender_discrimination_rescaled=rescale(anes08$percieved_gender_discrimination) 
anes12$percieved_gender_discrimination_rescaled=rescale(anes12$percieved_gender_discrimination) 
anes16$percieved_gender_discrimination_rescaled=rescale(anes16$percieved_gender_discrimination) 
anes20$percieved_gender_discrimination_rescaled=rescale(anes20$percieved_gender_discrimination) 

#Rescale Variables
anes04$percieved_gender_discrimination_rescaled=rescale(anes04$percieved_gender_discrimination) 
anes08$percieved_gender_discrimination_rescaled=rescale(anes08$percieved_gender_discrimination) 
anes12$percieved_gender_discrimination_rescaled=rescale(anes12$percieved_gender_discrimination) 
anes16$percieved_gender_discrimination_rescaled=rescale(anes16$percieved_gender_discrimination) 
anes20$percieved_gender_discrimination_rescaled=rescale(anes20$percieved_gender_discrimination) 
```

Hostile Sexism
```{r}
#2016

#HS1: Innocent remakrs as sexist
anes16$V161510 %>% attr("label")
anes16$V161510 %>% attr("labels")

table(anes16$V161507)
anes16$innocentremarks_as_sexist=ifelse(anes16$V161507==5,1,
                                      ifelse(anes16$V161507==4,2,
                                             ifelse(anes16$V161507==3,3,
                                                    ifelse(anes16$V161507==2,4,
                                                           ifelse(anes16$V161507==1,5,NA)))))

#HS2: Appreciate what men do
table(anes16$V161508)
anes16$appreicate_men_fully=ifelse(anes16$V161508==5,1,
                                      ifelse(anes16$V161508==4,2,
                                             ifelse(anes16$V161508==3,3,
                                                    ifelse(anes16$V161508==2,4,
                                                           ifelse(anes16$V161508==1,5,NA)))))

cor(anes16$innocentremarks_as_sexist, anes16$appreicate_men_fully, use = "complete.obs") #Checks out

#HS3: Women Seek Power by controlling men
table(anes16$V161509)
anes16$women_seek_controlmen_for_power=ifelse(anes16$V161509==5,1,
                                      ifelse(anes16$V161509==4,2,
                                             ifelse(anes16$V161509==3,3,
                                                    ifelse(anes16$V161509==2,4,
                                                           ifelse(anes16$V161509==1,5,NA)))))
cor(anes16$innocentremarks_as_sexist, anes16$women_seek_controlmen_for_power, use = "complete.obs") #Checks out
cor(anes16$appreicate_men_fully, anes16$women_seek_controlmen_for_power, use = "complete.obs") #Checks out

#HS4: Tight LEash
table(anes16$V161510)
anes16$tight_leash=ifelse(anes16$V161510==5,1,
                                      ifelse(anes16$V161510==4,2,
                                             ifelse(anes16$V161510==3,3,
                                                    ifelse(anes16$V161510==2,4,
                                                           ifelse(anes16$V161510==1,5,NA)))))
cor(anes16$innocentremarks_as_sexist, anes16$tight_leash, use = "complete.obs") #Checks out
cor(anes16$appreicate_men_fully, anes16$tight_leash, use = "complete.obs") #Checks out
cor(anes16$women_seek_controlmen_for_power, anes16$tight_leash, use = "complete.obs") #Checks out

library(ltm)
ca=anes16[,c("innocentremarks_as_sexist","appreicate_men_fully","women_seek_controlmen_for_power","tight_leash")]
cronbach.alpha(ca,na.rm = T) #0.789


anes16$hostile_sexism_index=anes16$innocentremarks_as_sexist+anes16$appreicate_men_fully+anes16$women_seek_controlmen_for_power+anes16$tight_leash



#2020
#HS1: Innocent remakrs as sexist
table(anes20$V201639)
anes20$innocentremarks_as_sexist=ifelse(anes20$V201639==5,1,
                                      ifelse(anes20$V201639==4,2,
                                             ifelse(anes20$V201639==3,3,
                                                    ifelse(anes20$V201639==2,4,
                                                           ifelse(anes20$V201639==1,5,NA)))))

#HS3: Women Seek Power by controlling men
table(anes20$V201640)
anes20$women_seek_controlmen_for_power=ifelse(anes20$V201640==5,1,
                                      ifelse(anes20$V201640==4,2,
                                             ifelse(anes20$V201640==3,3,
                                                    ifelse(anes20$V201640==2,4,
                                                           ifelse(anes20$V201640==1,5,NA)))))
cor(anes20$innocentremarks_as_sexist, anes20$women_seek_controlmen_for_power, use = "complete.obs") #Checks out

library(ltm)
ca=anes20[,c("innocentremarks_as_sexist","women_seek_controlmen_for_power")]
cronbach.alpha(ca,na.rm = T) #Checks out
anes20$hostile_sexism_index=anes20$innocentremarks_as_sexist+anes20$women_seek_controlmen_for_power



#Create blank variables in the 2004-2012 data sets
anes04$innocentremarks_as_sexist=NA
anes04$appreicate_men_fully=NA
anes04$women_seek_controlmen_for_power=NA
anes04$tight_leash=NA
anes04$hostile_sexism_index=NA


anes08$innocentremarks_as_sexist=NA
anes08$appreicate_men_fully=NA
anes08$women_seek_controlmen_for_power=NA
anes08$tight_leash=NA
anes08$hostile_sexism_index=NA

anes12$innocentremarks_as_sexist=NA
anes12$appreicate_men_fully=NA
anes12$women_seek_controlmen_for_power=NA
anes12$tight_leash=NA
anes12$hostile_sexism_index=NA

anes20$appreicate_men_fully=NA
anes20$tight_leash=NA


#Rescale Variables
anes16$hostile_sexism_index=rescale(anes16$hostile_sexism_index)
anes20$hostile_sexism_index=rescale(anes20$hostile_sexism_index)
```

Feeling Thermometers towards feminists
```{r}
#2004
table(anes04$V045059)
anes04$ft_feminists=ifelse(anes04$V045059 <0 |anes04$V045059 > 100  ,NA, anes04$V045059)
table(anes04$ft_feminists)

#2008
table(anes08$V085064d)
anes08$ft_feminists=ifelse(anes08$V085064d <0 ,NA, anes08$V085064d)
table(anes08$ft_feminists)

#2012
table(anes12$ftgr_feminists)
anes12$ft_feminists=ifelse(anes12$ftgr_feminists <0,NA, anes12$ftgr_feminists)
table(anes12$ft_feminists)

#2016
table(anes16$V162096)
anes16$ft_feminists=ifelse(anes16$V162096 <0|anes16$V162096 >100  ,NA, anes16$V162096)
table(anes16$ft_feminists)

#2020
table(anes20$V202160)
anes20$ft_feminists=ifelse(anes20$V202160 <0|anes20$V202160 >100  ,NA, anes20$V202160)
table(anes20$ft_feminists)


#Reverse code variables
summary(anes04$ft_feminists)
summary(anes04$reversecode)

anes04$ft_feminists=(anes04$ft_feminists) * (-1)
anes08$ft_feminists=(anes08$ft_feminists) * (-1)
anes12$ft_feminists=(anes12$ft_feminists) * (-1)
anes16$ft_feminists=(anes16$ft_feminists) * (-1)
anes20$ft_feminists=(anes20$ft_feminists)* (-1)
#Rescale Variables
anes04$ft_feminists=rescale(anes04$ft_feminists) 
anes08$ft_feminists=rescale(anes08$ft_feminists) 
anes12$ft_feminists=rescale(anes12$ft_feminists) 
anes16$ft_feminists=rescale(anes16$ft_feminists) 
anes20$ft_feminists=rescale(anes20$ft_feminists) 

```

Attitudes towards feminists (2016 &2020 only)...all coded to the negative
```{r}
# Consider yourself a feminist
table(anes16$V161345)
anes16$feministID=ifelse(anes16$V161345 <1,NA, anes16$V161345)
table(anes16$feministID)
                       
#How well does feminist describe you
table(anes16$V161346)
anes16$feministdescribe=ifelse(anes16$V161346 <1,NA, anes16$V161346)
table(anes16$feministdescribe)

#How important is being a feminist
table(anes16$V161347)
anes16$feminist_importance=ifelse(anes16$V161347 <1,NA, anes16$V161347)
table(anes16$feminist_importance)
summary(anes16$feminist_importance)
anes16$feminist_importance[anes16$feministdescribe==5]=5 #these respondents originally did not receive this question
table(anes16$feminist_importance)
summary(anes16$feminist_importance)


#How important is being anti-feminist
table(anes16$V161349)



#DOES R CONSIDER THEMSELF A FEMINIST OR ANTI-FEMINIST
table(anes20$V202475)

#How important is being a feminist
table(anes20$V202476)



```

#Main IV
2004 Racial Resentment
```{r}
#Conditions since slavery make it hard
table(anes04$V045194)

anes04$slavery_hard= ifelse(anes04$V045194 < 0 |anes04$V045194 >5 ,NA,anes04$V045194)
table(anes04$slavery_hard)

#Blacks have gotten less than deserved
table(anes04$V045195)
anes04$blacks_less_than_deserved= ifelse(anes04$V045195 < 0|anes04$V045195 >5,NA,anes04$V045195)
table(anes04$blacks_less_than_deserved)

cor(anes04$slavery_hard, anes04$blacks_less_than_deserved, use = "complete.obs") #Checks out


#Blacks try harder
table(anes04$V045196)
anes04$blacks_try_harder=ifelse(anes04$V045196==5,1,
                            ifelse(anes04$V045196==4,2, 
                                   ifelse(anes04$V045196==3,3,
                                          ifelse(anes04$V045196==2,4,
                                                 ifelse(anes04$V045196==1,5,NA)))))
table(anes04$blacks_try_harder)


cor(anes04$slavery_hard, anes04$blacks_try_harder, use = "complete.obs") #Checks out
cor(anes04$blacks_less_than_deserved, anes04$blacks_try_harder, use = "complete.obs") #Checks out


#Blacks Special Favors
table(anes04$V045193)
anes04$blacks_speacial_favors=ifelse(anes04$V045193==5,1,
                            ifelse(anes04$V045193==4,2, 
                                   ifelse(anes04$V045193==3,3,
                                          ifelse(anes04$V045193==2,4,
                                                 ifelse(anes04$V045193==1,5,NA)))))
table(anes04$blacks_speacial_favors)

cor(anes04$slavery_hard, anes04$blacks_speacial_favors, use = "complete.obs") #Checks out
cor(anes04$blacks_less_than_deserved, anes04$blacks_speacial_favors, use = "complete.obs") #Checks out
cor(anes04$blacks_try_harder, anes04$blacks_speacial_favors, use = "complete.obs") #Checks out

ca=anes04[,c("slavery_hard","blacks_less_than_deserved","blacks_try_harder","blacks_speacial_favors")]
cronbach.alpha(ca,na.rm = T) #Checks out

anes04$racial_resentment=anes04$slavery_hard+anes04$blacks_less_than_deserved+anes04$blacks_try_harder+anes04$blacks_speacial_favors


table(is.na(anes04$slavery_hard))
table(is.na(anes04$blacks_less_than_deserved))
table(is.na(anes04$blacks_try_harder))
table(is.na(anes04$blacks_speacial_favors))

table(is.na(anes04$racial_resentment))


```

2008 Racial Resentment
```{r}
#Conditions since slavery make it hard
table(anes08$V085144)
anes08$slavery_hard= ifelse(anes08$V085144 < 0,NA,anes08$V085144)
table(anes08$slavery_hard)

#Blacks have gotten less than deserved
table(anes08$V085145)
anes08$blacks_less_than_deserved= ifelse(anes08$V085145 < 0,NA,anes08$V085145)
table(anes08$blacks_less_than_deserved)

cor(anes08$slavery_hard, anes08$blacks_less_than_deserved, use = "complete.obs") #Checks out



#Blacks try harder
table(anes08$V085146)
anes08$blacks_try_harder=ifelse(anes08$V085146==5,1,
                            ifelse(anes08$V085146==4,2, 
                                   ifelse(anes08$V085146==3,3,
                                          ifelse(anes08$V085146==2,4,
                                                 ifelse(anes08$V085146==1,5,NA)))))
table(anes08$blacks_try_harder)


cor(anes08$slavery_hard, anes08$blacks_try_harder, use = "complete.obs") #Checks out
cor(anes08$blacks_less_than_deserved, anes08$blacks_try_harder, use = "complete.obs") #Checks out


#Blacks Speacial Favors
table(anes08$V085143)
anes08$blacks_speacial_favors=ifelse(anes08$V085143==5,1,
                            ifelse(anes08$V085143==4,2, 
                                   ifelse(anes08$V085143==3,3,
                                          ifelse(anes08$V085143==2,4,
                                                 ifelse(anes08$V085143==1,5,NA)))))
table(anes08$blacks_speacial_favors)

cor(anes08$slavery_hard, anes08$blacks_speacial_favors, use = "complete.obs") #Checks out
cor(anes08$blacks_less_than_deserved, anes08$blacks_speacial_favors, use = "complete.obs") #Checks out
cor(anes08$blacks_try_harder, anes08$blacks_speacial_favors, use = "complete.obs") #Checks out

ca=anes08[,c("slavery_hard","blacks_less_than_deserved","blacks_try_harder","blacks_speacial_favors")]
cronbach.alpha(ca,na.rm = T) #Checks out

anes08$racial_resentment=anes08$slavery_hard+anes08$blacks_less_than_deserved+anes08$blacks_try_harder+anes08$blacks_speacial_favors


table(is.na(anes08$racial_resentment))
```

2012 Racial Resentment
```{r}
#Conditions since slavery make it hard
table(anes12$resent_slavery)
anes12$slavery_hard= ifelse(anes12$resent_slavery < 0,NA,anes12$resent_slavery)
table(anes12$slavery_hard)

#Blacks have gotten less than deserved
table(anes12$resent_deserve)
anes12$blacks_less_than_deserved= ifelse(anes12$resent_deserve < 0,NA,anes12$resent_deserve)
table(anes12$blacks_less_than_deserved)

cor(anes12$slavery_hard, anes12$blacks_less_than_deserved, use = "complete.obs") #Checks out



#Blacks try harder
table(anes12$resent_try)
anes12$blacks_try_harder=ifelse(anes12$resent_try==5,1,
                            ifelse(anes12$resent_try==4,2, 
                                   ifelse(anes12$resent_try==3,3,
                                          ifelse(anes12$resent_try==2,4,
                                                 ifelse(anes12$resent_try==1,5,NA)))))
table(anes12$blacks_try_harder)


cor(anes12$slavery_hard, anes12$blacks_try_harder, use = "complete.obs") #Checks out
cor(anes12$blacks_less_than_deserved, anes12$blacks_try_harder, use = "complete.obs") #Checks out


#Blacks Speacial Favors
table(anes12$resent_workway)
anes12$blacks_speacial_favors=ifelse(anes12$resent_workway==5,1,
                            ifelse(anes12$resent_workway==4,2, 
                                   ifelse(anes12$resent_workway==3,3,
                                          ifelse(anes12$resent_workway==2,4,
                                                 ifelse(anes12$resent_workway==1,5,NA)))))
table(anes12$blacks_speacial_favors)

cor(anes12$slavery_hard, anes12$blacks_speacial_favors, use = "complete.obs") #Checks out
cor(anes12$blacks_less_than_deserved, anes12$blacks_speacial_favors, use = "complete.obs") #Checks out
cor(anes12$blacks_try_harder, anes12$blacks_speacial_favors, use = "complete.obs") #Checks out

ca=anes12[,c("slavery_hard","blacks_less_than_deserved","blacks_try_harder","blacks_speacial_favors")]
cronbach.alpha(ca,na.rm = T) #Checks out

anes12$racial_resentment=anes12$slavery_hard+anes12$blacks_less_than_deserved+anes12$blacks_try_harder+anes12$blacks_speacial_favors
```

2016 Racial Resentment
```{r}
#Conditions since slavery make it hard
table(anes16$V162212)
anes16$slavery_hard= ifelse(anes16$V162212 < 0,NA,anes16$V162212)
table(anes16$slavery_hard)

#Blacks have gotten less than deserved
table(anes16$V162213)
anes16$blacks_less_than_deserved= ifelse(anes16$V162213 < 0,NA,anes16$V162213)
table(anes16$blacks_less_than_deserved)

cor(anes16$slavery_hard, anes16$blacks_less_than_deserved, use = "complete.obs") #Checks out


#Blacks try harder
table(anes16$V162214)
anes16$blacks_try_harder=ifelse(anes16$V162214==5,1,
                            ifelse(anes16$V162214==4,2, 
                                   ifelse(anes16$V162214==3,3,
                                          ifelse(anes16$V162214==2,4,
                                                 ifelse(anes16$V162214==1,5,NA)))))
table(anes16$blacks_try_harder)

cor(anes16$slavery_hard, anes16$blacks_try_harder, use = "complete.obs") #Checks out
cor(anes16$blacks_less_than_deserved, anes16$blacks_try_harder, use = "complete.obs") #Checks out

#Blacks Speacial Favors
table(anes16$V162211)
anes16$blacks_speacial_favors=ifelse(anes16$V162211==5,1,
                            ifelse(anes16$V162211==4,2, 
                                   ifelse(anes16$V162211==3,3,
                                          ifelse(anes16$V162211==2,4,
                                                 ifelse(anes16$V162211==1,5,NA)))))
table(anes16$blacks_speacial_favors)

cor(anes16$slavery_hard, anes16$blacks_speacial_favors, use = "complete.obs") #Checks out
cor(anes16$blacks_less_than_deserved, anes16$blacks_speacial_favors, use = "complete.obs") #Checks out
cor(anes16$blacks_try_harder, anes16$blacks_speacial_favors, use = "complete.obs") #Checks out

ca=anes16[,c("slavery_hard","blacks_less_than_deserved","blacks_try_harder","blacks_speacial_favors")]
cronbach.alpha(ca,na.rm = T) #Checks out

anes16$racial_resentment=anes16$slavery_hard+anes16$blacks_less_than_deserved+anes16$blacks_try_harder+anes16$blacks_speacial_favors


table(is.na(anes16$racial_resentment))
```

2020 Racial Resentment
```{r}
#Conditions since slavery make it hard
table(anes20$V202301)
anes20$slavery_hard= ifelse(anes20$V202301 < 0,NA,anes20$V202301)
table(anes20$slavery_hard)

#Blacks have gotten less than deserved
table(anes20$V202302)
anes20$blacks_less_than_deserved= ifelse(anes20$V202302 < 0,NA,anes20$V202302)
table(anes20$blacks_less_than_deserved)

cor(anes20$slavery_hard, anes20$blacks_less_than_deserved, use = "complete.obs") #Checks out


#Blacks try harder
table(anes20$V202303)
anes20$blacks_try_harder=ifelse(anes20$V202303==5,1,
                            ifelse(anes20$V202303==4,2, 
                                   ifelse(anes20$V202303==3,3,
                                          ifelse(anes20$V202303==2,4,
                                                 ifelse(anes20$V202303==1,5,NA)))))
table(anes20$blacks_try_harder)

cor(anes20$slavery_hard, anes20$blacks_try_harder, use = "complete.obs") #Checks out
cor(anes20$blacks_less_than_deserved, anes20$blacks_try_harder, use = "complete.obs") #Checks out

#Blacks Speacial Favors
table(anes20$V202300)
anes20$blacks_speacial_favors=ifelse(anes20$V202300==5,1,
                            ifelse(anes20$V202300==4,2, 
                                   ifelse(anes20$V202300==3,3,
                                          ifelse(anes20$V202300==2,4,
                                                 ifelse(anes20$V202300==1,5,NA)))))
table(anes20$blacks_speacial_favors)

cor(anes20$slavery_hard, anes20$blacks_speacial_favors, use = "complete.obs") #Checks out
cor(anes20$blacks_less_than_deserved, anes20$blacks_speacial_favors, use = "complete.obs") #Checks out
cor(anes20$blacks_try_harder, anes20$blacks_speacial_favors, use = "complete.obs") #Checks out

ca=anes20[,c("slavery_hard","blacks_less_than_deserved","blacks_try_harder","blacks_speacial_favors")]
cronbach.alpha(ca,na.rm = T) #Checks out

anes20$racial_resentment=anes20$slavery_hard+anes20$blacks_less_than_deserved+anes20$blacks_try_harder+anes20$blacks_speacial_favors


table(is.na(anes20$racial_resentment))

#Rescale Variables
anes04$racial_resentment=rescale(anes04$racial_resentment) 
anes08$racial_resentment=rescale(anes08$racial_resentment) 
anes12$racial_resentment=rescale(anes12$racial_resentment) 
anes16$racial_resentment=rescale(anes16$racial_resentment) 
anes20$racial_resentment=rescale(anes20$racial_resentment) 
```

#Alternative Racial Resentment Measures

Feeling Thermometers towards Blacks
```{r}
#2004
table(anes04$V045077)
anes04$ft_blacks=ifelse(anes04$V045077 <0 |anes04$V045077 > 100  ,NA, anes04$V045077)
table(anes04$ft_blacks)

#2008
table(anes08$V085064y)
anes08$ft_blacks=ifelse(anes08$V085064y <0 ,NA, anes08$V085064y)
table(anes08$ft_blacks)

#2012
table(anes12$ftcasi_black)
anes12$ft_blacks=ifelse(anes12$ftcasi_black <0,NA, anes12$ftcasi_black)
table(anes12$ft_blacks)

#2016
table(anes16$V162312)
anes16$ft_blacks=ifelse(anes16$V162312 <0|anes16$V162312 >100  ,NA, anes16$V162312)
table(anes16$ft_blacks)

#2020
table(anes20$V202480)
anes20$ft_blacks=ifelse(anes20$V202480 <0|anes20$V202480 >100  ,NA, anes20$V202480)
table(anes20$ft_blacks)

anes04$ft_blacks=(anes04$ft_blacks) * (-1)
anes08$ft_blacks=(anes08$ft_blacks) * (-1)
anes12$ft_blacks=(anes12$ft_blacks) * (-1)
anes16$ft_blacks=(anes16$ft_blacks) * (-1)
anes20$ft_blacks=(anes20$ft_blacks)* (-1)

#Rescale Variables
anes04$ft_blacks=rescale(anes04$ft_blacks) 
anes08$ft_blacks=rescale(anes08$ft_blacks) 
anes12$ft_blacks=rescale(anes12$ft_blacks) 
anes16$ft_blacks=rescale(anes16$ft_blacks) 
anes20$ft_blacks=rescale(anes20$ft_blacks) 
```

Feeling Thermometers towards whites
```{r}
#2004
table(anes04$V045086)
anes04$ft_whites=ifelse(anes04$V045086 <0 |anes04$V045086 > 100  ,NA, anes04$V045086)
table(anes04$ft_whites)

#2008
table(anes08$V085065c)
anes08$ft_whites=ifelse(anes08$V085065c <0 ,NA, anes08$V085065c)
table(anes08$ft_whites)

#2012
table(anes12$ftcasi_white)
anes12$ft_whites=ifelse(anes12$ftcasi_white <0,NA, anes12$ftcasi_white)
table(anes12$ft_whites)

#2016
table(anes16$V162314)
anes16$ft_whites=ifelse(anes16$V162314 <0|anes16$V162314 >100  ,NA, anes16$V162314)
table(anes16$ft_whites)

#2020
table(anes20$V202482)
anes20$ft_whites=ifelse(anes20$V202482 <0|anes20$V202482 >100  ,NA, anes20$V202482)
table(anes20$ft_whites)

#Rescale Variables
anes04$ft_whites=rescale(anes04$ft_whites) 
anes08$ft_whites=rescale(anes08$ft_whites) 
anes12$ft_whites=rescale(anes12$ft_whites) 
anes16$ft_whites=rescale(anes16$ft_whites) 
anes20$ft_whites=rescale(anes20$ft_whites) 
```

Feeling Thermometers towards jews
```{r}
#2004
table(anes04$V045061)
anes04$ft_jews=ifelse(anes04$V045061 <0 |anes04$V045061 > 100  ,NA, anes04$V045061)
table(anes04$ft_jews)

#2008
table(anes08$V085064f)
anes08$ft_jews=ifelse(anes08$V085064f <0 ,NA, anes08$V085064f)
table(anes08$ft_jews)

#2012
anes12$ft_jews=NA
table(anes12$ft_jews)

#2016
table(anes16$V162108)
anes16$ft_jews=ifelse(anes16$V162108 <0|anes16$V162108 >100  ,NA, anes16$V162108)
table(anes16$ft_jews)

#2020
table(anes20$V202170)
anes20$ft_jews=ifelse(anes20$V202170 <0|anes20$V202170 >100  ,NA, anes20$V202170)
table(anes20$ft_jews)

anes04$ft_jews=(anes04$ft_jews) * (-1)
anes08$ft_jews=(anes08$ft_jews) * (-1)
anes16$ft_jews=(anes16$ft_jews) * (-1)
anes20$ft_jews=(anes20$ft_jews)* (-1)

#Rescale Variables
anes04$ft_jews=rescale(anes04$ft_jews) 
anes08$ft_jews=rescale(anes08$ft_jews) 
anes16$ft_jews=rescale(anes16$ft_jews) 
anes20$ft_jews=rescale(anes20$ft_jews) 
```

Feeling Thermometers towards asians
```{r}
#2004
table(anes04$V045075)
anes04$ft_asians=ifelse(anes04$V045075 <0 |anes04$V045075 > 100  ,NA, anes04$V045075)
table(anes04$ft_asians)

#2008
table(anes08$V085064v)
anes08$ft_asians=ifelse(anes08$V085064v <0 ,NA, anes08$V085064v)
table(anes08$ft_asians)

#2012
table(anes12$ftcasi_asian)
anes12$ft_asians=ifelse(anes12$ftcasi_asian <0,NA, anes12$ftcasi_asian)
table(anes12$ft_asians)

#2016
table(anes16$V162310)
anes16$ft_asians=ifelse(anes16$V162310 <0|anes16$V162310 >100  ,NA, anes16$V162310)
table(anes16$ft_asians)

#2020
table(anes20$V202477)
anes20$ft_asians=ifelse(anes20$V202477 <0|anes20$V202477 >100  ,NA, anes20$V202477)
table(anes20$ft_asians)

#Reverse Code variable
anes04$ft_asians=(anes04$ft_asians) * (-1)
anes08$ft_asians=(anes08$ft_asians) * (-1)
anes12$ft_asians=(anes12$ft_asians) * (-1)
anes16$ft_asians=(anes16$ft_asians) * (-1)
anes20$ft_asians=(anes20$ft_asians)* (-1)

#Rescale Variables
anes04$ft_asians=rescale(anes04$ft_asians) 
anes08$ft_asians=rescale(anes08$ft_asians) 
anes12$ft_asians=rescale(anes12$ft_asians) 
anes16$ft_asians=rescale(anes16$ft_asians) 
anes20$ft_asians=rescale(anes20$ft_asians) 
```

Feeling Thermometers towards latinos
```{r}
#2004
table(anes04$V045056)
anes04$ft_latinos=ifelse(anes04$V045056 <0 |anes04$V045056 > 100  ,NA, anes04$V045056)
table(anes04$ft_latinos)

#2008
table(anes08$V085064s)
anes08$ft_latinos=ifelse(anes08$V085064s <0 ,NA, anes08$V085064s)
table(anes08$ft_latinos)

#2012
table(anes12$ftcasi_hisp)
anes12$ft_latinos=ifelse(anes12$ftcasi_hisp <0,NA, anes12$ftcasi_hisp)
table(anes12$ft_latinos)

#2016
table(anes16$V162311)
anes16$ft_latinos=ifelse(anes16$V162311 <0|anes16$V162311 >100  ,NA, anes16$V162311)
table(anes16$ft_latinos)

#2020
table(anes20$V202479)
anes20$ft_latinos=ifelse(anes20$V202479 <0|anes20$V202479 >100  ,NA, anes20$V202479)
table(anes20$ft_latinos)

#Reverse code variables
#Reverse Code variable
anes04$ft_latinos=(anes04$ft_latinos) * (-1)
anes08$ft_latinos=(anes08$ft_latinos) * (-1)
anes12$ft_latinos=(anes12$ft_latinos) * (-1)
anes16$ft_latinos=(anes16$ft_latinos) * (-1)
anes20$ft_latinos=(anes20$ft_latinos)* (-1)
#Rescale Variables
anes04$ft_latinos=rescale(anes04$ft_latinos) 
anes08$ft_latinos=rescale(anes08$ft_latinos) 
anes12$ft_latinos=rescale(anes12$ft_latinos) 
anes16$ft_latinos=rescale(anes16$ft_latinos) 
anes20$ft_latinos=rescale(anes20$ft_latinos) 
```

Feeling Thermometers towards illegal immigrants/aliens
```{r}
#2004
table(anes04$V045081)
anes04$ft_aliens=ifelse(anes04$V045081 <0 |anes04$V045081 > 100  ,NA, anes04$V045081)
table(anes04$ft_aliens)

#2008
table(anes08$V085065a)
anes08$ft_aliens=ifelse(anes08$V085065a <0 ,NA, anes08$V085065a)
table(anes08$ft_aliens)

#2012
table(anes12$ftcasi_illegal)
anes12$ft_aliens=ifelse(anes12$ftcasi_illegal <0,NA, anes12$ftcasi_illegal)
table(anes12$ft_aliens)

#2016
table(anes16$V162313)
anes16$ft_aliens=ifelse(anes16$V162313 <0|anes16$V162313 >100  ,NA, anes16$V162313)
table(anes16$ft_aliens)

#2020
table(anes20$V202481)
anes20$ft_aliens=ifelse(anes20$V202481 <0|anes20$V202481 >100  ,NA, anes20$V202481)
table(anes20$ft_aliens)

#Reverse Code variable
anes04$ft_aliens=(anes04$ft_aliens) * (-1)
anes08$ft_aliens=(anes08$ft_aliens) * (-1)
anes12$ft_aliens=(anes12$ft_aliens) * (-1)
anes16$ft_aliens=(anes16$ft_aliens) * (-1)
anes20$ft_aliens=(anes20$ft_aliens)* (-1)

#Rescale Variables
anes04$ft_aliens=rescale(anes04$ft_aliens) 
anes08$ft_aliens=rescale(anes08$ft_aliens) 
anes12$ft_aliens=rescale(anes12$ft_aliens) 
anes16$ft_aliens=rescale(anes16$ft_aliens) 
anes20$ft_aliens=rescale(anes20$ft_aliens) 
```


#Other Controls
2004 Controls
```{r}
#Female
table(anes04$V041109a)
anes04$woman=ifelse(anes04$V041109a==1,0,
                          ifelse(anes04$V041109a==2,1,NA))
table(anes04$woman)

#Feminist ID (N/A)


#Party Id
table(anes04$V043116)
anes04$pid3=ifelse(anes04$V043116 >6,NA,
                   ifelse(anes04$V043116 < 3,0,
                       ifelse(anes04$V043116 ==3,1,2)))
table(anes04$pid3)

anes04$pid=ifelse(anes04$V043116 > 6,NA,anes04$V043116)
table(anes04$pid)

#Ideology
table(anes04$V043085)
table(anes04$V043085a)

anes04$ideology=ifelse(anes04$V043085 > 8,NA,anes04$V043085)
summary(anes04$ideology)

table(anes04$V043086)

table(anes04$V043086)
anes04$ideology_3pt=ifelse(anes04$V043086 ==1,1,
                           ifelse(anes04$V043086 ==3,2,
                                  ifelse(anes04$V043086 ==5,3,NA )))
summary(anes04$ideology_3pt)

anes12$ideology_3pt=ifelse(anes12$libcpre_choose==1 | anes12$libcpre_self==1| anes12$libcpre_self==2| anes12$libcpre_self==3,1,
                           ifelse(anes12$libcpre_choose==2 | anes12$libcpre_self==5| anes12$libcpre_self==6| anes12$libcpre_self==7,3,
                                  ifelse(anes12$libcpre_choose==3,2,
                                          ifelse(anes12$libcpre_self==4, 2,NA)))) #makes sure to account for self identified moderates now marked as NAs

#economic evaluations
table(anes04$V043097)
anes04$economic_evaluation=ifelse(anes04$V043097==1,2,
                            ifelse(anes04$V043097==3,1,
                                   ifelse(anes04$V043097==5,0,NA)))
table(anes04$economic_evaluation)
anes04$economic_evaluation=rescale(anes04$economic_evaluation)

#Moral Traditionalism, higher score equals greater conservatism

table(anes04$V045189) #World Should Adjust views of 
anes04$moral_traditionalism=ifelse(anes04$V045189>5,NA, anes04$V045189)
table(anes04$moral_traditionalism) #World Should Adjust views of 
anes04$moral_traditionalism=rescale(anes04$moral_traditionalism)

#Egalatariansum- 4 item index

#Society Equal Opportunity
table(anes04$V045212)
anes04$society_equal_opportunity=ifelse(anes04$V045212==1,5,
                                    ifelse(anes04$V045212==2,4,
                                           ifelse(anes04$V045212==3,3,
                                                  ifelse(anes04$V045212==4,2,
                                                         ifelse(anes04$V045212==5,1,NA)))))
table(anes04$society_equal_opportunity)
summary(anes04$society_equal_opportunity)



#Worry less about quality
table(anes04$V045215)
anes04$worry_less_equality=ifelse(anes04$V045215 < 0 | anes04$V045215 > 5 ,NA,anes04$V045215) 
table(anes04$worry_less_equality)
summary(anes04$worry_less_equality)

cor(anes04$society_equal_opportunity,anes04$worry_less_equality,use="complete.obs")


#More chance no big deal
table(anes04$V045216)
anes04$more_lifechances_notbigdeal=ifelse(anes04$V045216 < 0| anes04$V045216 > 5,NA,anes04$V045216) 
table(anes04$more_lifechances_notbigdeal)
summary(anes04$more_lifechances_notbigdeal)

cor(anes04$more_lifechances_notbigdeal,anes04$society_equal_opportunity,use="complete.obs")
cor(anes04$more_lifechances_notbigdeal,anes04$worry_less_equality,use="complete.obs")



#Fair treatment less issues
table(anes04$V045217)
anes04$treatpeoplefairly_lessissues=ifelse(anes04$V045217==1,5,
                                    ifelse(anes04$V045217==2,4,
                                           ifelse(anes04$V045217==3,3,
                                                  ifelse(anes04$V045217==4,2,
                                                         ifelse(anes04$V045217==5,1,NA)))))
table(anes04$treatpeoplefairly_lessissues)
summary(anes04$treatpeoplefairly_lessissues)


cor(anes04$treatpeoplefairly_lessissues,anes04$society_equal_opportunity,use="complete.obs")
cor(anes04$treatpeoplefairly_lessissues,anes04$worry_less_equality,use="complete.obs")
cor(anes04$treatpeoplefairly_lessissues,anes04$more_lifechances_notbigdeal,use="complete.obs")

library(ltm)
ca=anes04[,c("society_equal_opportunity","worry_less_equality","more_lifechances_notbigdeal","treatpeoplefairly_lessissues")]
cronbach.alpha(ca,na.rm = T) #Checks out

anes04$egalitarianism=anes04$society_equal_opportunity+anes04$society_equal_opportunity+anes04$more_lifechances_notbigdeal+anes04$treatpeoplefairly_lessissues



#Scope of government- 3 item index

table(anes04$V045150)#govt bigger to adress issues or too incolved as it is
anes04$government_size=ifelse(anes04$V045150==1,0,
                              ifelse(anes04$V045150==2,1,NA))

table(anes04$V045151) #free market
anes04$strong_government=ifelse(anes04$V045151 ==2,0,
                                ifelse(anes04$V045151==1,1,NA))

cor(anes04$government_size,anes04$strong_government,use="complete.obs") #checks out


table(anes04$V045152) #less government is better or more government could do
anes04$gov_do_more=ifelse(anes04$V045152==1,0,
                          ifelse(anes04$V045152==2,1,NA))
table(anes04$gov_do_more)
cor(anes04$gov_do_more,anes04$government_size,use="complete.obs") #checks out
cor(anes04$gov_do_more,anes04$strong_government,use="complete.obs") #checks out


library(ltm)
ca=anes04[,c("government_size","gov_do_more", "strong_government")]
cronbach.alpha(ca,na.rm = T) #Checks out

anes04$scope_of_gov=anes04$government_size+anes04$gov_do_more+anes04$strong_government

#Office Recall, correct, incorrect, or didn;t try are the options
table(anes04$V045162)
anes04$officerecall_1=ifelse(anes04$V045162==1,1,0)
table(anes04$officerecall_1)

table(anes04$V045163)
anes04$officerecall_2=ifelse(anes04$V045163==1,1,0)
table(anes04$officerecall_2)

table(anes04$V045164)
anes04$officerecall_3=ifelse(anes04$V045164==1,1,0)
table(anes04$officerecall_3)


anes04$officerecall_4=ifelse(anes04$V045165==1,1,0)
table(anes04$officerecall_4)


anes04$politicalknowledge=anes04$officerecall_1+anes04$officerecall_2+ anes04$officerecall_3+anes04$officerecall_4
summary(anes04$politicalknowledge)

#Age
table(anes04$V043250)
anes04$age=ifelse(anes04$V043250 < 0, NA,anes04$V043250)
table(anes04$age)


#Education
table(anes04$V043254)
anes04$education=anes04$V043254

#Married
table(anes04$V043251)
anes04$married=ifelse(anes04$V043251 ==8,NA,
                      ifelse(anes04$V043251 == 1,1,0))
table(anes04$married)

#Income
table(anes04$V043293x)
anes04$income=ifelse(anes04$V043293x ==0 |anes04$V043293x > 23 ,NA, anes04$V043293x)
table(anes04$income)


#Homemaker the home
table(anes04$V043260b)
anes04$homemaker=ifelse(anes04$V043260b ==9,NA, 
                        ifelse(anes04$V043260b==7,1,0))
table(anes04$homemaker)

#Biblical Liberalism
table(anes04$V043222)
anes04$biblical_literalism=ifelse(anes04$V043222==1,3,
                                  ifelse(anes04$V043222==2,2,
                                         ifelse(anes04$V043222==3,1,NA)))
table(anes04$biblical_literalism)


#Church attendance
table(anes04$V043223)
table(anes04$V043224)

anes04$church_attendance=ifelse(anes04$V043223 ==5,0,
                                 ifelse(anes04$V043224 ==5,0,
                                        ifelse(anes04$V043224==4,1,
                                               ifelse(anes04$V043224==3,2,
                                                       ifelse(anes04$V043224==2,3,
                                                              ifelse(anes04$V043224==1,4,NA))))))
table(anes04$church_attendance)



#Religion, 3 dummy variables, no clarification for evangelical, so only 3 categories
table(anes04$V043247)
anes04$religion_v2=as.factor(ifelse(anes04$V043247==0 | anes04$V043247 >7,NA,
                                 ifelse(anes04$V043247 ==1,1,
                                        ifelse(anes04$V043247 ==2,3,4))))
                                        
                                  
table(anes04$religion_v2)

anes04$religion=anes04$religion_v2


#region
table(anes04$V041205)
anes04$region=as.factor(anes04$V041205)
anes04$region= factor(anes04$region,levels = c("3",1,2,4))
table(anes04$region)

#Rescale Variables
anes04$pid=rescale(anes04$pid)
anes04$ideology_3pt=rescale(anes04$ideology_3pt)
anes04$egalitarianism=rescale(anes04$egalitarianism)
anes04$scope_of_gov=rescale(anes04$scope_of_gov)
anes04$politicalknowledge=rescale(anes04$politicalknowledge)
anes04$age=rescale(anes04$age)
anes04$education=rescale(anes04$education)
anes04$income=rescale(anes04$income)
anes04$biblical_literalism=rescale(anes04$biblical_literalism)
anes04$church_attendance=rescale(anes04$church_attendance)

```

2008 Controls
```{r}
#Female
table(anes08$V081101)
anes08$woman=ifelse(anes08$V081101==1,0,
                          ifelse(anes08$V081101==2,1,NA))
table(anes08$woman)

#Feminist (N/A)


#Party Id
table(anes08$V083098x)

anes08$pid3=ifelse(anes08$V083098x <0,NA,
                   ifelse(anes08$V083098x >=0 & anes08$V083098x < 3,0,
                       ifelse(anes08$V083098x ==3,1,2)))
table(anes08$pid3)

anes08$pid=ifelse(anes08$V083098x <0,NA,anes08$V083098x)
table(anes08$pid)

#Ideology
table(anes08$V083069)
anes08$ideology=ifelse(anes08$V083069 <0 |anes08$V083069 > 7,NA,anes08$V083069)
table(anes08$ideology)

table(anes08$V083069x)
anes08$ideology_3pt=ifelse(anes08$V083069x ==1,1,
                           ifelse(anes08$V083069x ==3,2,
                                  ifelse(anes08$V083069x ==5,3,NA )))
table(anes08$ideology_3pt)


#economic evaluations
table(anes08$V083083)
anes08$economic_evaluation=ifelse(anes08$V083083==1,2,
                            ifelse(anes08$V083083==3,1,
                                   ifelse(anes08$V083083==5,0,NA)))
table(anes08$economic_evaluation)
anes08$economic_evaluation=rescale(anes08$economic_evaluation)

table(anes08$V085139) #World Should Adjust views of 
anes08$moral_traditionalism=ifelse(anes08$V085139>5,NA, anes08$V085139)
table(anes08$moral_traditionalism) #World Should Adjust views of 
anes08$moral_traditionalism=rescale(anes08$moral_traditionalism)

#Egalatariansum- 4 item index

#Society Equal Opportunity
table(anes08$V085162)
anes08$society_equal_opportunity=ifelse(anes08$V085162==1,5,
                                    ifelse(anes08$V085162==2,4,
                                           ifelse(anes08$V085162==3,3,
                                                  ifelse(anes08$V085162==4,2,
                                                         ifelse(anes08$V085162==5,1,NA)))))
table(anes08$society_equal_opportunity)
summary(anes08$society_equal_opportunity)



#Worry less about quality
table(anes08$V085165)
anes08$worry_less_equality=ifelse(anes08$V085165 < 0,NA,anes08$V085165) 
table(anes08$worry_less_equality)
summary(anes08$worry_less_equality)

cor(anes08$society_equal_opportunity,anes08$worry_less_equality,use="complete.obs")


#More chance no big deal
table(anes08$V085166)
anes08$more_lifechances_notbigdeal=ifelse(anes08$V085166 < 0,NA,anes08$V085166) 
table(anes08$more_lifechances_notbigdeal)
summary(anes08$more_lifechances_notbigdeal)

cor(anes08$more_lifechances_notbigdeal,anes08$society_equal_opportunity,use="complete.obs")
cor(anes08$more_lifechances_notbigdeal,anes08$worry_less_equality,use="complete.obs")



#Fair treatment less issues
table(anes08$V085167)
anes08$treatpeoplefairly_lessissues=ifelse(anes08$V085167==1,5,
                                    ifelse(anes08$V085167==2,4,
                                           ifelse(anes08$V085167==3,3,
                                                  ifelse(anes08$V085167==4,2,
                                                         ifelse(anes08$V085167==5,1,NA)))))
table(anes08$treatpeoplefairly_lessissues)
summary(anes08$treatpeoplefairly_lessissues)


cor(anes08$treatpeoplefairly_lessissues,anes08$society_equal_opportunity,use="complete.obs")
cor(anes08$treatpeoplefairly_lessissues,anes08$worry_less_equality,use="complete.obs")
cor(anes08$treatpeoplefairly_lessissues,anes08$more_lifechances_notbigdeal,use="complete.obs")

library(ltm)
ca=anes08[,c("society_equal_opportunity","worry_less_equality","more_lifechances_notbigdeal","treatpeoplefairly_lessissues")]
cronbach.alpha(ca,na.rm = T) #Checks out

anes08$egalitarianism=anes08$society_equal_opportunity+anes08$society_equal_opportunity+anes08$more_lifechances_notbigdeal+anes08$treatpeoplefairly_lessissues



#Scope of government- 3 item index

table(anes08$V085105)#govt bigger to adress issues or too incolved as it is
anes08$government_size=ifelse(anes08$V085105==1,0,
                              ifelse(anes08$V085105==2,1,NA))

table(anes08$V085106) #similar government or free market question but asked as would it be good for society to have more or less government regulation, 
anes08$strong_government=ifelse(anes08$V085106 ==2,0,
                                ifelse(anes08$V085106==1,1,NA))

cor(anes08$government_size,anes08$strong_government,use="complete.obs") #checks out


table(anes08$V085107) #less government is better or more government could do
anes08$gov_do_more=ifelse(anes08$V085107==1,0,
                          ifelse(anes08$V085107==2,1,NA))
table(anes08$gov_do_more)
cor(anes08$gov_do_more,anes08$government_size,use="complete.obs") #checks out
cor(anes08$gov_do_more,anes08$strong_government,use="complete.obs") #checks out


library(ltm)
ca=anes08[,c("government_size","gov_do_more", "strong_government")]
cronbach.alpha(ca,na.rm = T) #Checks out

anes08$scope_of_gov=anes08$government_size+anes08$gov_do_more+anes08$strong_government

#Office Recall-not included, the code for this is restricted and says they are still revising the coding to the open ended responses document, do we want to add that to this, after manually voding the values for this oursleves across all 5 levels?


#anes08$V085120a %>% attr("label")
#anes08$V085121a %>% attr("label")


#table(anes08$V085120a)

#anes08$officerecall_1=ifelse(anes08$ofcrec_speaker_correct <0,NA, 
  #                     ifelse(anes08$ofcrec_speaker_correct==0,0,1))
#table(anes08$officerecall_1)

#anes08$officerecall_2=ifelse(anes08$ofcrec_vp_correct <0,NA, 
 #                       ifelse(anes08$ofcrec_vp_correct==0,0,1))
#table(anes08$officerecall_2)

#anes08$officerecall_3=ifelse(anes08$ofcrec_pmuk_correct <0,NA, 
 #                       ifelse(anes08$ofcrec_pmuk_correct==0,0,1))
#table(anes08$officerecall_3)

#anes08$officerecall_4=ifelse(anes08$ofcrec_cj_correct <0,NA, 
 #                       ifelse(anes08$ofcrec_cj_correct==0,0,1))
#table(anes08$officerecall_4)


#anes08$politicalknowledge=anes08$officerecall_1+anes08$officerecall_2+ anes08$officerecall_3+anes08$officerecall_4
#summary(anes08$politicalknowledge)

#Age
table(anes08$V083215x)
anes08$age=ifelse(anes08$V083215x < 0, NA,anes08$V083215x)
table(anes08$age)


#Education
table(anes08$V083218x)
anes08$education=ifelse(anes08$V083218x < 0, NA,anes08$V083218x)
table(anes08$education)

#Married
table(anes08$V083216x)
anes08$married=ifelse(anes08$V083216x <0,NA,
                      ifelse(anes08$V083216x == 1,1,0))

#Income
table(anes08$V083248x)
anes08$income=ifelse(anes08$V083248x <0,NA, anes08$V083248x)


#Homemaker the home
table(anes08$V083222a)
anes08$homemaker=ifelse(anes08$V083222a <0,NA, 
                        ifelse(anes08$V083222a==7,1,0))

#Biblical Literalism
table(anes08$V083184)
anes08$biblical_literalism=ifelse(anes08$V083184 ==3,1,
                                  ifelse(anes08$V083184 ==2,2,
                                         ifelse(anes08$V083184 ==1,3,NA)))
table(anes08$biblical_literalism)

#church attendance

table(anes08$V083186)
table(anes08$V083186a)


anes08$church_attendance= ifelse(anes08$V083186 ==5 |anes08$V083186a ==5 ,0,
                                        ifelse(anes08$V083186a==4,1,
                                               ifelse(anes08$V083186a==3,2,
                                                       ifelse(anes08$V083186a==2,3,
                                                              ifelse(anes08$V083186a==1,4,NA)))))

table(anes08$church_attendance)



#Religion, 3 dummy variables
table(anes08$V083203) #To capture evangelical 
table(anes08$V083185b)
anes08$religion=as.factor(ifelse (anes08$V083185b <0,NA,
                                  ifelse(anes08$V083185b==1 &anes08$V083203==1 ,2,
                                       ifelse(anes08$V083185b==1,1,
                                          ifelse(anes08$V083185b==2,3,4)))))

table(anes08$religion)        


#region
table(anes08$V081204)
anes08$region=as.factor(anes08$V081204)
anes08$region= factor(anes08$region,levels = c("3",1,2,4))
table(anes08$region)


#Rescale Variables
anes08$pid=rescale(anes08$pid)
anes08$ideology_3pt=rescale(anes08$ideology_3pt)
anes08$egalitarianism=rescale(anes08$egalitarianism)
anes08$scope_of_gov=rescale(anes08$scope_of_gov)
#anes08$politicalknowledge=rescale(anes08$politicalknowledge)
anes08$age=rescale(anes08$age)
anes08$education=rescale(anes08$education)
anes08$income=rescale(anes08$income)
anes08$biblical_literalism=rescale(anes08$biblical_literalism)
anes08$church_attendance=rescale(anes08$church_attendance)
```

2012 Controls
```{r}
#Female

table(anes12$gender_respondent_x)
anes12$woman=ifelse(anes12$gender_respondent_x==1,0,
                          ifelse(anes12$gender_respondent_x==2,1,NA))
table(anes12$woman)

#Feminist (N/A)


#Party Id
table(anes12$pid_x)
anes12$pid3=ifelse(anes12$pid_x <0,NA,
                   ifelse(anes12$pid_x >0 & anes12$pid_x < 4,0,
                       ifelse(anes12$pid_x ==4,1,2)))
table(anes12$pid3)

anes12$pid=ifelse(anes12$pid_x <0,NA,anes12$pid_x)
table(anes12$pid)

#Ideology
table(anes12$libcpre_self)
anes12$ideology=ifelse(anes12$libcpre_self <0 |anes12$libcpre_self > 7,NA,anes12$libcpre_self) #7 point version which drops all those who are asked to choose as a follow up question, may come back to this and try creating a 3 point item
table(anes12$libcpre_self)
table(anes12$libcpre_choose)


anes12$ideology_3pt=ifelse(anes12$libcpre_choose==1 | anes12$libcpre_self==1| anes12$libcpre_self==2| anes12$libcpre_self==3,1,
                           ifelse(anes12$libcpre_choose==2 | anes12$libcpre_self==5| anes12$libcpre_self==6| anes12$libcpre_self==7,3,
                                  ifelse(anes12$libcpre_choose==3,2,
                                          ifelse(anes12$libcpre_self==4, 2,NA)))) #makes sure to account for self identified moderates now marked as NAs


summary(anes12$ideology_3pt)
summary(anes12$ideology)


#economic evaluations
table(anes12$econ_ecpast)
anes12$economic_evaluation=ifelse(anes12$econ_ecpast==1,2,
                            ifelse(anes12$econ_ecpast==3,1,
                                   ifelse(anes12$econ_ecpast==5,0,NA)))
table(anes12$economic_evaluation)
anes12$economic_evaluation=rescale(anes12$economic_evaluation)


#Moral Traditionalism, higher score equals greater conservatism

table(anes12$trad_adjust) #World Should Adjust views of 
anes12$moral_traditionalism=ifelse(anes12$trad_adjust>5,NA, anes12$trad_adjust)
table(anes12$moral_traditionalism) #World Should Adjust views of 
anes12$moral_traditionalism=rescale(anes12$moral_traditionalism)

#Egalatariansum- 4 item index

#Society Equal Opportunity
table(anes12$egal_equal)
anes12$society_equal_opportunity=ifelse(anes12$egal_equal==1,5,
                                    ifelse(anes12$egal_equal==2,4,
                                           ifelse(anes12$egal_equal==3,3,
                                                  ifelse(anes12$egal_equal==4,2,
                                                         ifelse(anes12$egal_equal==5,1,NA)))))
table(anes12$society_equal_opportunity)
summary(anes12$society_equal_opportunity)



#Worry less about quality
table(anes12$egal_worryless)
anes12$worry_less_equality=ifelse(anes12$egal_worryless < 0,NA,anes12$egal_worryless) 
table(anes12$worry_less_equality)
summary(anes12$worry_less_equality)

cor(anes12$society_equal_opportunity,anes12$worry_less_equality,use="complete.obs")


#More chance no big deal
table(anes12$egal_notbigprob)
anes12$more_lifechances_notbigdeal=ifelse(anes12$egal_notbigprob < 0,NA,anes12$egal_notbigprob) 
table(anes12$more_lifechances_notbigdeal)
summary(anes12$more_lifechances_notbigdeal)

cor(anes12$more_lifechances_notbigdeal,anes12$society_equal_opportunity,use="complete.obs")
cor(anes12$more_lifechances_notbigdeal,anes12$worry_less_equality,use="complete.obs")



#Fair treatment less issues
table(anes12$egal_fewerprobs)
anes12$egal_fewerprobs %>% attr("label")
anes12$egal_fewerprobs %>% attr("labels")

anes12$treatpeoplefairly_lessissues=ifelse(anes12$egal_fewerprobs==1,5,
                                    ifelse(anes12$egal_fewerprobs==2,4,
                                           ifelse(anes12$egal_fewerprobs==3,3,
                                                  ifelse(anes12$egal_fewerprobs==4,2,
                                                         ifelse(anes12$egal_fewerprobs==5,1,NA)))))
table(anes12$treatpeoplefairly_lessissues)
summary(anes12$treatpeoplefairly_lessissues)


cor(anes12$treatpeoplefairly_lessissues,anes12$society_equal_opportunity,use="complete.obs")
cor(anes12$treatpeoplefairly_lessissues,anes12$worry_less_equality,use="complete.obs")
cor(anes12$treatpeoplefairly_lessissues,anes12$more_lifechances_notbigdeal,use="complete.obs")

library(ltm)
ca=anes12[,c("society_equal_opportunity","worry_less_equality","more_lifechances_notbigdeal","treatpeoplefairly_lessissues")]
cronbach.alpha(ca,na.rm = T) #Checks out

anes12$egalitarianism=anes12$society_equal_opportunity+anes12$society_equal_opportunity+anes12$more_lifechances_notbigdeal+anes12$treatpeoplefairly_lessissues



#Scope of government- 3 item index

table(anes12$govrole_big)#govt bigger to address more issues or too involved as it is
anes12$government_size=ifelse(anes12$govrole_big==1,0,
                              ifelse(anes12$govrole_big==2,1,NA))

table(anes12$govrole_market) #simialr government or free market question but asked as would it be good for society to have more or less governme t gegulation, 
anes12$strong_government=ifelse(anes12$govrole_market ==2,0,
                                ifelse(anes12$govrole_market==1,1,NA))

cor(anes12$government_size,anes12$strong_government,use="complete.obs") #checks out


table(anes12$govrole_lessmore) #less government is better or more government could do
anes12$gov_do_more=ifelse(anes12$govrole_lessmore==1,0,
                          ifelse(anes12$govrole_lessmore==2,1,NA))
table(anes12$gov_do_more)
cor(anes12$gov_do_more,anes12$government_size,use="complete.obs") #checks out
cor(anes12$gov_do_more,anes12$strong_government,use="complete.obs") #checks out


library(ltm)
ca=anes12[,c("government_size","gov_do_more", "strong_government")]
cronbach.alpha(ca,na.rm = T) #Checks out

anes12$scope_of_gov=anes12$government_size+anes12$gov_do_more+anes12$strong_government

#Office Recall
table(anes12$ofcrec_speaker_correct)
anes12$officerecall_1=ifelse(anes12$ofcrec_speaker_correct <0,NA, 
                        ifelse(anes12$ofcrec_speaker_correct==0,0,1))
table(anes12$officerecall_1)

anes12$officerecall_2=ifelse(anes12$ofcrec_vp_correct <0,NA, 
                        ifelse(anes12$ofcrec_vp_correct==0,0,1))
table(anes12$officerecall_2)

anes12$officerecall_3=ifelse(anes12$ofcrec_pmuk_correct <0,NA, 
                        ifelse(anes12$ofcrec_pmuk_correct==0,0,1))
table(anes12$officerecall_3)

anes12$officerecall_4=ifelse(anes12$ofcrec_cj_correct <0,NA, 
                        ifelse(anes12$ofcrec_cj_correct==0,0,1))
table(anes12$officerecall_4)


anes12$politicalknowledge=anes12$officerecall_1+anes12$officerecall_2+ anes12$officerecall_3+anes12$officerecall_4
summary(anes12$politicalknowledge)

#Age
table(anes12$dem_age_r_x)
anes12$age=ifelse(anes12$dem_age_r_x < 0, NA,anes12$dem_age_r_x)
table(anes12$age)


#Education
table(anes12$dem_edu)




table(anes12$dem_edugroup_x)#less categories

anes12$education=ifelse(anes12$dem_edu < 0 | anes12$dem_edu > 16, NA,anes12$dem_edu)

#Married
table(anes12$dem_marital)
anes12$married=ifelse(anes12$dem_marital <0,NA,
                      ifelse(anes12$dem_marital == 1| anes12$dem_marital==2,1,0)) #ANES 2012-2020 distinguishes wheter reposndnet states if their spouse is present or absent

#Income
table(anes12$inc_incgroup_pre)
anes12$income=ifelse(anes12$inc_incgroup_pre <0,NA, anes12$inc_incgroup_pre)


#Homemaker the home
table(anes12$dem_empstatus_1digitfin_x)
anes12$homemaker=ifelse(anes12$dem_empstatus_1digitfin_x <0,NA, 
                        ifelse(anes12$dem_empstatus_1digitfin_x==7,1,0))

#Biblical Literalism
table(anes12$relig_wordgod)
anes12$biblical_literalism=ifelse(anes12$relig_wordgod == 1,3,
                                  ifelse(anes12$relig_wordgod == 2,2,
                                         ifelse(anes12$relig_wordgod == 3,1,NA)))
                                  
#church attendance
table(anes12$relig_church)
table(anes12$relig_churchoft)

anes12$church_attendance= ifelse(anes12$relig_church ==2,0,
                                 ifelse(anes12$relig_churchoft ==5,0,
                                        ifelse(anes12$relig_churchoft==4,1,
                                               ifelse(anes12$relig_churchoft==3,2,
                                                       ifelse(anes12$relig_churchoft==2,3,
                                                              ifelse(anes12$relig_churchoft==1,4,NA))))))
table(anes12$church_attendance)

#Religion, 3 dummy variables
table(anes12$relig_7cat_x)
anes12$religion=as.factor(ifelse (anes12$relig_7cat_x <0,NA,
                            ifelse(anes12$relig_7cat_x==1,1,
                                ifelse(anes12$relig_7cat_x==2,2,
                                       ifelse(anes12$relig_7cat_x==4,3,4)))))

table(anes12$religion)                      

#region
table(anes12$sample_region)
anes12$region=as.factor(anes12$sample_region)
anes12$region= factor(anes12$region,levels = c("3",1,2,4))
table(anes12$region)


#Rescale Variables
anes12$pid=rescale(anes12$pid)
anes12$ideology_3pt=rescale(anes12$ideology_3pt)
anes12$egalitarianism=rescale(anes12$egalitarianism)
anes12$scope_of_gov=rescale(anes12$scope_of_gov)
anes12$politicalknowledge=rescale(anes12$politicalknowledge)
anes12$age=rescale(anes12$age)
anes12$education=rescale(anes12$education)
anes12$income=rescale(anes12$income)
anes12$biblical_literalism=rescale(anes12$biblical_literalism)
anes12$church_attendance=rescale(anes12$church_attendance)
```

2016 Controls
```{r}
#Female
table(anes16$V161342)
anes16$woman=ifelse(anes16$V161342==1,0,
                          ifelse(anes16$V161342==2,1,NA))
table(anes16$woman)

#Feminist Battery
table(anes16$V161345) #consider self feminsits?
anes16$consider_self_feminist=ifelse(anes16$V161345 == 1,3,
                      ifelse(anes16$V161345 == 2,2,
                      ifelse(anes16$V161345 == 3,1,NA)))
table(anes16$consider_self_feminist)


table(anes16$V161346) #How well does feminist describe you?
anes16$describe_self_feminist=ifelse(anes16$V161346 == 1,5,
                              ifelse(anes16$V161346 == 2,4,
                              ifelse(anes16$V161346 == 3,3, 
                              ifelse(anes16$V161346 == 4,2,
                              ifelse(anes16$V161346 == 5,1,NA)))))
table(anes16$describe_self_feminist)

cor(anes16$consider_self_feminist, anes16$describe_self_feminist, use = "complete.obs") #Checks out

table(anes16$V161347) #How important is being a feminist?
anes16$importance_self_feminist=ifelse(anes16$V161347 == 1,5,
                              ifelse(anes16$V161347 == 2,4,
                              ifelse(anes16$V161347 == 3,3, 
                              ifelse(anes16$V161347 == 4,2,
                              ifelse(anes16$V161347 == 5,1,NA)))))
table(anes16$importance_self_feminist)

cor(anes16$consider_self_feminist, anes16$importance_self_feminist, use = "complete.obs") #Checks out
cor(anes16$describe_self_feminist, anes16$importance_self_feminist, use = "complete.obs") #Checks out

table(anes16$V161348) #How well does anti-feminist describe you

anes16$describe_self_antifeminist=ifelse(anes16$V161348 <0,NA, anes16$V161348)
cor(anes16$consider_self_feminist, anes16$describe_self_antifeminist, use = "complete.obs") #Checks out
cor(anes16$describe_self_feminist, anes16$describe_self_antifeminist, use = "complete.obs") #Checks out
cor(anes16$importance_self_feminist, anes16$describe_self_antifeminist, use = "complete.obs") #Checks out



table(anes16$V161349) #How important is being anti feminist
anes16$importance_self_antifeminist=ifelse(anes16$V161349 <0,NA, anes16$V161349)
cor(anes16$consider_self_feminist, anes16$importance_self_antifeminist, use = "complete.obs") #Checks out
cor(anes16$describe_self_feminist, anes16$importance_self_antifeminist, use = "complete.obs") #Checks out
cor(anes16$importance_self_feminist, anes16$importance_self_antifeminist, use = "complete.obs") #Checks out
cor(anes16$describe_self_antifeminist, anes16$importance_self_antifeminist, use = "complete.obs") #Checks out


#Pary Id
table(anes16$V161158x)
anes16$pid3=ifelse(anes16$V161158x <0,NA,
                   ifelse(anes16$V161158x >0 & anes16$V161158x < 4,0,
                       ifelse(anes16$V161158x ==4,1,2)))
table(anes16$pid3)

anes16$pid=ifelse(anes16$V161158x <0,NA,anes16$V161158x)
table(anes16$pid)

#Ideology
table(anes16$V161126)
anes16$ideology=ifelse(anes16$V161126 <0 |anes16$V161126 > 7,NA,anes16$V161126)

table(anes16$V161126)
table(anes16$V161127)


anes16$ideology_3pt=ifelse(anes16$V161127==1 | anes16$V161126==1| anes16$V161126==2| anes16$V161126==3,1,
                           ifelse(anes16$V161127==2 | anes16$V161126==5| anes16$V161126==6| anes16$V161126==7,3,
                                  ifelse(anes16$V161127==3,2,
                                          ifelse(anes16$V161126==4, 2,NA)))) #makes sure to account for self identified moderates now marked as NAs

summary(anes16$ideology)
summary(anes16$ideology_3pt)

#economic evaluations
table(anes16$V161140)
anes16$economic_evaluation=ifelse(anes16$V161140==1,2,
                            ifelse(anes16$V161140==3,1,
                                   ifelse(anes16$V161140==5,0,NA)))
table(anes16$economic_evaluation)
anes16$economic_evaluation=rescale(anes16$economic_evaluation)

#Moral Traditionalism, higher score equals greater conservatism

table(anes16$V162207) #World Should Adjust views of 
anes16$moral_traditionalism=ifelse(anes16$V162207>5,NA, anes16$V162207)
table(anes16$moral_traditionalism) #World Should Adjust views of 
anes16$moral_traditionalism=rescale(anes16$moral_traditionalism)


#Egalatariansum- 4 item index

#Society Equal Opportunity
table(anes16$V162243)
anes16$society_equal_opportunity=ifelse(anes16$V162243==1,5,
                                    ifelse(anes16$V162243==2,4,
                                           ifelse(anes16$V162243==3,3,
                                                  ifelse(anes16$V162243==4,2,
                                                         ifelse(anes16$V162243==5,1,NA)))))
table(anes16$society_equal_opportunity)
summary(anes16$society_equal_opportunity)

summary(anes16$egalitarianism)


#Worry less about quality
table(anes16$V162244)
anes16$worry_less_equality=ifelse(anes16$V162244 < 0,NA,anes16$V162244) 
table(anes16$worry_less_equality)
summary(anes16$worry_less_equality)

cor(anes16$society_equal_opportunity,anes16$worry_less_equality,use="complete.obs")


#More chance no big deal
table(anes16$V162245)
anes16$more_lifechances_notbigdeal=ifelse(anes16$V162245 < 0,NA,anes16$V162245) 
table(anes16$more_lifechances_notbigdeal)
summary(anes16$more_lifechances_notbigdeal)

cor(anes16$more_lifechances_notbigdeal,anes16$society_equal_opportunity,use="complete.obs")
cor(anes16$more_lifechances_notbigdeal,anes16$worry_less_equality,use="complete.obs")



#Fair treatment less issues
table(anes16$V162246)
anes16$treatpeoplefairly_lessissues=ifelse(anes16$V162246==1,5,
                                    ifelse(anes16$V162246==2,4,
                                           ifelse(anes16$V162246==3,3,
                                                  ifelse(anes16$V162246==4,2,
                                                         ifelse(anes16$V162246==5,1,NA)))))
table(anes16$treatpeoplefairly_lessissues)
summary(anes16$treatpeoplefairly_lessissues)


cor(anes16$treatpeoplefairly_lessissues,anes16$society_equal_opportunity,use="complete.obs")
cor(anes16$treatpeoplefairly_lessissues,anes16$worry_less_equality,use="complete.obs")
cor(anes16$treatpeoplefairly_lessissues,anes16$more_lifechances_notbigdeal,use="complete.obs")

library(ltm)
ca=anes16[,c("society_equal_opportunity","worry_less_equality","more_lifechances_notbigdeal","treatpeoplefairly_lessissues")]
cronbach.alpha(ca,na.rm = T) #Checks out

anes16$egalitarianism=anes16$society_equal_opportunity+anes16$society_equal_opportunity+anes16$more_lifechances_notbigdeal+anes16$treatpeoplefairly_lessissues



#Scope of government- 3 item index

table(anes16$V162183)#govt bigger to adress issues or too incolved as it is
anes16$government_size=ifelse(anes16$V162183==1,0,
                              ifelse(anes16$V162183==2,1,NA))

table(anes16$V162184) #government or free market
anes16$strong_government=ifelse(anes16$V162184 ==2,0,
                                ifelse(anes16$V162184==1,1,NA))

cor(anes16$government_size,anes16$strong_government,use="complete.obs") #checks out


table(anes16$V162185) #less government is better or more government could do
anes16$gov_do_more=ifelse(anes16$V162185==1,0,
                          ifelse(anes16$V162185==2,1,NA))

cor(anes16$gov_do_more,anes16$government_size,use="complete.obs") #checks out
cor(anes16$gov_do_more,anes16$strong_government,use="complete.obs") #checks out

library(ltm)
ca=anes16[,c("government_size","strong_government","gov_do_more")]
cronbach.alpha(ca,na.rm = T) #Checks out

anes16$scope_of_gov=anes16$government_size+anes16$strong_government+anes16$gov_do_more

#Office Recall
table(anes16$V162072)
anes16$officerecall_1=ifelse(anes16$V162072 <0,NA, 
                        ifelse(anes16$V162072==1,1,0))
table(anes16$officerecall_1)

anes16$officerecall_2=ifelse(anes16$V162073b <0,NA, 
                        ifelse(anes16$V162073b==1,1,0))
table(anes16$officerecall_2)

anes16$officerecall_3=ifelse(anes16$V162074b <0,NA, 
                        ifelse(anes16$V162074b==1,1,0))
table(anes16$officerecall_3)

anes16$officerecall_4=ifelse(anes16$V162075b <0,NA, 
                        ifelse(anes16$V162075b==1,1,0))
table(anes16$officerecall_4)

anes16$officerecall_5=ifelse(anes16$V162076b <0,NA, 
                        ifelse(anes16$V162076b==1,1,0))
table(anes16$officerecall_5)

anes16$politicalknowledge=anes16$officerecall_1+anes16$officerecall_2+ anes16$officerecall_3+anes16$officerecall_4+anes16$officerecall_5
summary(anes16$politicalknowledge)

#Age
table(anes16$V161267)
anes16$age=ifelse(anes16$V161267 < 0, NA,anes16$V161267)
table(anes16$age)


#Education
table(anes16$V161270)
anes16$education=ifelse(anes16$V161270 < 0 | anes16$V161270 > 16, NA,anes16$V161270)

#Married
table(anes16$V161268)
anes16$married=ifelse(anes16$V161268 <0,NA,
                      ifelse(anes16$V161268 == 1| anes16$V161268==2,1,0))

#Married
table(anes16$V161268)
anes16$married=ifelse(anes16$V161268 <0,NA,
                      ifelse(anes16$V161268 == 1| anes16$V161268==2,1,0))

#Income
table(anes16$V161361x)

anes16$income=ifelse(anes16$V161361x <0,NA, anes16$V161361x)


#Homeaker the home
table(anes16$V161276x)
anes16$homemaker=ifelse(anes16$V161276x <0,NA, 
                        ifelse(anes16$V161276x==7,1,0))

#Biblical Literalism
table(anes16$V161243)
anes16$biblical_literalism=ifelse(anes16$V161243 ==1,3,
                                  ifelse(anes16$V161243 ==2,2,
                                         ifelse(anes16$V161243 ==3,1,NA)))

#church attendance
table(anes16$V161244)
table(anes16$V161245)

anes16$church_attendance= ifelse(anes16$V161244 ==2,0,
                                 ifelse(anes16$V161245 ==5,0,
                                        ifelse(anes16$V161245==4,1,
                                               ifelse(anes16$V161245==3,2,
                                                       ifelse(anes16$V161245==2,3,
                                                              ifelse(anes16$V161245==1,4,NA))))))
table(anes16$V161245)
table(anes16$church_attendance)



#Religion, 3 dummy variables
table(anes16$V161265x)
anes16$religion=as.factor(ifelse (anes16$V161265x <0,NA,
                            ifelse(anes16$V161265x==1,1,
                                ifelse(anes16$V161265x==2,2,
                                       ifelse(anes16$V161265x==4,3,4)))))

table(anes16$religion)                     

#region
table(anes16$V163003)
anes16$region=as.factor(anes16$V163003)
anes16$region= factor(anes16$region,levels = c("3",1,2,4))
table(anes16$region)


#Rescale Variables
anes16$pid=rescale(anes16$pid)
anes16$ideology_3pt=rescale(anes16$ideology_3pt)
anes16$egalitarianism=rescale(anes16$egalitarianism)
anes16$scope_of_gov=rescale(anes16$scope_of_gov)
anes16$politicalknowledge=rescale(anes16$politicalknowledge)
anes16$age=rescale(anes16$age)
anes16$education=rescale(anes16$education)
anes16$income=rescale(anes16$income)
anes16$biblical_literalism=rescale(anes16$biblical_literalism)
anes16$church_attendance=rescale(anes16$church_attendance)
```

2020 Controls
```{r}
#Female
table(anes20$V201600)
anes20$woman=ifelse(anes20$V201600==1,0,
                          ifelse(anes20$V201600==2,1,NA))
table(anes20$woman)


#Feminist
table(anes20$consider_self_feminist)
anes20$consider_self_feminist=ifelse(anes20$V202475 <0,NA,
                       ifelse(anes20$V202475 ==1,3,
                               ifelse(anes20$V202475 ==3,2,
                                       ifelse(anes20$V202475 ==2,1,NA))))
table(anes20$consider_self_feminist)

table(anes20$consider_self_feminist)

table(anes20$V202476) #How important is being a feminist?
anes20$importance_self_feminist=ifelse(anes20$V202476 == 1,5,
                              ifelse(anes20$V202476 == 2,4,
                              ifelse(anes20$V202476 == 3,3, 
                              ifelse(anes20$V202476 == 4,2,
                              ifelse(anes20$V202476 == 5,1,NA)))))
table(anes20$importance_self_feminist)


#Party Id
table(anes20$V201231x)
anes20$pid3=ifelse(anes20$V201231x <0,NA,
                   ifelse(anes20$V201231x >0 & anes20$V201231x < 4,0,
                       ifelse(anes20$V201231x ==4,1,2)))
table(anes20$pid3)

anes20$pid=ifelse(anes20$V201231x <0,NA,anes20$V201231x)
table(anes20$pid)

#Ideology
table(anes20$V201200)
anes20$ideology=ifelse(anes20$V201200 <0 |anes20$V201200 > 7,NA,anes20$V201200)

table(anes20$V201200)
table(anes20$V201201)


anes20$ideology_3pt=ifelse(anes20$V201201==1 | anes20$V201200==1| anes20$V201200==2| anes20$V201200==3,1,
                           ifelse(anes20$V201201==2 | anes20$V201200==5| anes20$V201200==6| anes20$V201200==7,3,
                                  ifelse(anes20$V201201==3,2,
                                          ifelse(anes20$V201200==4, 2,NA)))) #makes sure to account for self identified moderates now marked as NAs

#economic evaluations
table(anes20$V201325)
anes20$economic_evaluation=ifelse(anes20$V201325==1,2,
                            ifelse(anes20$V201325==3,1,
                                   ifelse(anes20$V201325==5,0,NA)))
table(anes20$economic_evaluation)
anes20$economic_evaluation=rescale(anes20$economic_evaluation)

#Moral Traditionalism, higher score equals greater conservatism

table(anes20$V202264) #World Should Adjust views of 
anes20$moral_traditionalism=ifelse(anes20$V202264>5,NA, anes20$V202264)
table(anes20$moral_traditionalism) #World Should Adjust views of 
anes20$moral_traditionalism=rescale(anes20$moral_traditionalism)



#Egalatariansum- 4 item index

#Society Equal Opportunity
table(anes20$V202260)
anes20$society_equal_opportunity=ifelse(anes20$V202260==1,5,
                                    ifelse(anes20$V202260==2,4,
                                           ifelse(anes20$V202260==3,3,
                                                  ifelse(anes20$V202260==4,2,
                                                         ifelse(anes20$V202260==5,1,NA)))))
table(anes20$society_equal_opportunity)
summary(anes20$society_equal_opportunity)

summary(anes20$egalitarianism)


#Worry less about quality
table(anes20$V202261)
anes20$worry_less_equality=ifelse(anes20$V202261 < 0,NA,anes20$V202261) 
table(anes20$worry_less_equality)
summary(anes20$worry_less_equality)

cor(anes20$society_equal_opportunity,anes20$worry_less_equality,use="complete.obs")


#More chance no big deal
table(anes20$V202262)
anes20$more_lifechances_notbigdeal=ifelse(anes20$V202262 < 0,NA,anes20$V202262) 
table(anes20$more_lifechances_notbigdeal)
summary(anes20$more_lifechances_notbigdeal)

cor(anes20$more_lifechances_notbigdeal,anes20$society_equal_opportunity,use="complete.obs")
cor(anes20$more_lifechances_notbigdeal,anes20$worry_less_equality,use="complete.obs")



#Fair treatment less issues
table(anes20$V202263)
anes20$treatpeoplefairly_lessissues=ifelse(anes20$V202263==1,5,
                                    ifelse(anes20$V202263==2,4,
                                           ifelse(anes20$V202263==3,3,
                                                  ifelse(anes20$V202263==4,2,
                                                         ifelse(anes20$V202263==5,1,NA)))))
table(anes20$treatpeoplefairly_lessissues)
summary(anes20$treatpeoplefairly_lessissues)


cor(anes20$treatpeoplefairly_lessissues,anes20$society_equal_opportunity,use="complete.obs")
cor(anes20$treatpeoplefairly_lessissues,anes20$worry_less_equality,use="complete.obs")
cor(anes20$treatpeoplefairly_lessissues,anes20$more_lifechances_notbigdeal,use="complete.obs")

library(ltm)
ca=anes20[,c("society_equal_opportunity","worry_less_equality","more_lifechances_notbigdeal","treatpeoplefairly_lessissues")]
cronbach.alpha(ca,na.rm = T) #Checks out

anes20$egalitarianism=anes20$society_equal_opportunity+anes20$society_equal_opportunity+anes20$more_lifechances_notbigdeal+anes20$treatpeoplefairly_lessissues



#Scope of government- 3 item index

#table(anes20$V162183)#govt bigger to address issues or too incolved as it is
#anes20$government_size=ifelse(anes20$V162183==1,0,
                              #ifelse(anes20$V162183==2,1,NA))

table(anes20$V202256) #simialr government or free market question but asked as would it be good for society to have more or less governme t gegulation, 
#anes20$strong_government=ifelse(anes20$V202256 ==2,0,
 #                               ifelse(anes20$V202256==1,1,NA)), will need to recode

#cor(anes20$government_size,anes20$strong_government,use="complete.obs") #checks out


table(anes20$V202253) #less government is better or more government could do
anes20$gov_do_more=ifelse(anes20$V202253==1,0,
                          ifelse(anes20$V202253==2,1,NA))
table(anes20$gov_do_more)
#cor(anes20$gov_do_more,anes20$government_size,use="complete.obs") #checks out
#cor(anes20$gov_do_more,anes20$strong_government,use="complete.obs") #checks out

#V202256 



library(ltm)
#ca=anes20[,c("government_size","gov_do_more")]
#cronbach.alpha(ca,na.rm = T) #Checks out

anes20$scope_of_gov=anes20$gov_do_more

#Office Recall
table(anes20$V202136y)
anes20$officerecall_1=ifelse(anes20$V202136y <0,NA, 
                        ifelse(anes20$V202136y==1,1,0))
table(anes20$officerecall_1)

anes20$officerecall_2=ifelse(anes20$V202138y <0,NA, 
                        ifelse(anes20$V202138y==1,1,0))
table(anes20$officerecall_2)

anes20$officerecall_3=ifelse(anes20$V202139y1 <0,NA, 
                        ifelse(anes20$V202139y1==1,1,0))
table(anes20$officerecall_3)

anes20$officerecall_4=ifelse(anes20$V202140y1 <0,NA, 
                        ifelse(anes20$V202140y1==1,1,0))
table(anes20$officerecall_4)

anes20$officerecall_5=ifelse(anes20$V202142y2 <0,NA, 
                        ifelse(anes20$V202142y2==1,1,0))
table(anes20$officerecall_5)

anes20$politicalknowledge=anes20$officerecall_1+anes20$officerecall_2+ anes20$officerecall_3+anes20$officerecall_4+anes20$officerecall_5
summary(anes20$politicalknowledge)

#Age
table(anes20$V201507x)
anes20$age=ifelse(anes20$V201507x < 0, NA,anes20$V201507x)
table(anes20$age)


#Education
table(anes20$V201510)
anes20$education=ifelse(anes20$V201510 < 0 | anes20$V201510 > 8, NA,anes20$V201510)

#Married
table(anes20$V201508)
anes20$married=ifelse(anes20$V201508 <0,NA,
                      ifelse(anes20$V201508 == 1| anes20$V201508==2,1,0))

#Income
table(anes20$V201617x)

anes20$income=ifelse(anes20$V201617x <0,NA, anes20$V201617x)


#Homeaker the home
table(anes20$V201534x)
anes20$homemaker=ifelse(anes20$V201534x <0,NA, 
                        ifelse(anes20$V201534x==7,1,0))

#Biblical Literalism
table(anes20$V201434)
anes20$biblical_literalism=ifelse(anes20$V201434==1,3,
                                  ifelse(anes20$V201434==2,2,
                                         ifelse(anes20$V201434==3,1,NA)))

#church attendance
table(anes20$V201452)
table(anes20$V201453)

anes20$church_attendance= ifelse(anes20$V201452 ==2,0,
                                 ifelse(anes20$V201453 ==5,0,
                                        ifelse(anes20$V201453==4,1,
                                               ifelse(anes20$V201453==3,2,
                                                       ifelse(anes20$V201453==2,3,
                                                              ifelse(anes20$V201453==1,4,NA))))))
table(anes20$V161245)
table(anes20$church_attendance)



#Religion, 3 dummy variables
table(anes20$V201458x)
anes20$religion=as.factor(ifelse (anes20$V201458x <0,NA,
                            ifelse(anes20$V201458x==1,1,
                                ifelse(anes20$V201458x==2,2,
                                       ifelse(anes20$V201458x==5,3,4)))))

table(anes20$religion) 

#region
table(anes20$V203003)
anes20$region=as.factor(anes20$V203003)
anes20$region= factor(anes20$region,levels = c("3",1,2,4))
table(anes20$region)


#Rescale Variables
anes20$pid=rescale(anes20$pid)
anes20$ideology_3pt=rescale(anes20$ideology_3pt)
anes20$egalitarianism=rescale(anes20$egalitarianism)
anes20$scope_of_gov=rescale(anes20$scope_of_gov)
anes20$politicalknowledge=rescale(anes20$politicalknowledge)
anes20$age=rescale(anes20$age)
anes20$education=rescale(anes20$education)
anes20$income=rescale(anes20$income)
anes20$biblical_literalism=rescale(anes20$biblical_literalism)
```

Weight and Year Variables
```{r}
anes04$weight_variable=anes04$V040102
anes08$weight_variable=anes08$V080102
anes12$weight_variable=anes12$weight_full
anes16$weight_variable=anes16$V160102
anes20$weight_variable=anes20$V200010b


anes04$Year=2004
anes08$Year=2008
anes12$Year=2012
anes16$Year=2016
anes20$Year=2020
```

Create Race Variables
```{r}
#2004
anes04$V043299 %>% attr("labels")

table(anes04$V043299)
anes04$white=ifelse(anes04$V043299==50,1,0)
table(anes04$white) 

anes04$black=ifelse(anes04$V043299 > 16,1,0)
table(anes04$black)


#2008
anes08$V081102 %>% attr("labels")

table(anes08$V081102)
anes08$white=ifelse(anes08$V081102==1,1,0)
table(anes08$white) 
anes08$black=ifelse(anes08$V081102 ==2| anes08$V081102==3|anes08$V081102==6,1,0)
table(anes08$black) 

#2012
anes12$dem_raceeth_x %>% attr("labels")
table(anes12$dem_raceeth_x)
anes12$white=ifelse(anes12$dem_raceeth_x==1,1,0)
anes12$black=ifelse(anes12$dem_raceeth_x==2,1,0)
table(anes12$white)
table(anes12$black)


#2016
anes16$V161310x %>% attr("labels")
table(anes16$V161310x)
anes16$white=ifelse(anes16$V161310x==1,1,0)
anes16$black=ifelse(anes16$V161310x==2,1,0)
table(anes16$white) 
table(anes16$black) 

#2020
table(anes20$V201549x)
anes20$white=ifelse(anes20$V201549x==1,1,0)
anes20$black=ifelse(anes20$V201549x==2,1,0)
table(anes20$white)
table(anes20$black)





```

Create data set across years
```{r}
anes04$modern_sexism_indexv2=anes04$modern_sexism_index
anes08$modern_sexism_indexv2=anes08$modern_sexism_index
anes20$modern_sexism_indexv2=anes20$modern_sexism_index

anes04_subset=anes04[,c("morefamilyties","working_mother_bond","fatherwork_mother_home","traditional_values_index","speacialfavors_women","women_complaints_make_more_problems","modern_sexism_index","modern_sexism_indexv2","percieved_gender_discrimination","percieved_gender_discrimination_rescaled","innocentremarks_as_sexist","appreicate_men_fully","women_seek_controlmen_for_power","tight_leash","hostile_sexism_index","ft_feminists","slavery_hard","blacks_less_than_deserved","blacks_try_harder","blacks_speacial_favors","racial_resentment","ft_blacks","ft_whites","ft_jews","ft_asians","ft_latinos","ft_aliens","woman","pid","egalitarianism","scope_of_gov","ideology_3pt","economic_evaluation","moral_traditionalism","age","education","married","income","homemaker","biblical_literalism","church_attendance","religion","white","region","weight_variable","Year")]

anes08_subset=anes08[,c("morefamilyties","working_mother_bond","fatherwork_mother_home","traditional_values_index","speacialfavors_women","women_complaints_make_more_problems","modern_sexism_index","modern_sexism_indexv2","percieved_gender_discrimination","percieved_gender_discrimination_rescaled","innocentremarks_as_sexist","appreicate_men_fully","women_seek_controlmen_for_power","tight_leash","hostile_sexism_index","ft_feminists","slavery_hard","blacks_less_than_deserved","blacks_try_harder","blacks_speacial_favors","racial_resentment","ft_blacks","ft_whites","ft_jews","ft_asians","ft_latinos","ft_aliens","woman","pid","egalitarianism","scope_of_gov","ideology_3pt","economic_evaluation","moral_traditionalism","age","education","married","income","homemaker","biblical_literalism","church_attendance","religion","white","region","weight_variable","Year")]

anes12_subset=anes12[,c("morefamilyties","working_mother_bond","fatherwork_mother_home","traditional_values_index","speacialfavors_women","women_complaints_make_more_problems","modern_sexism_index","modern_sexism_indexv2","percieved_gender_discrimination","percieved_gender_discrimination_rescaled","innocentremarks_as_sexist","appreicate_men_fully","women_seek_controlmen_for_power","tight_leash","hostile_sexism_index","ft_feminists","slavery_hard","blacks_less_than_deserved","blacks_try_harder","blacks_speacial_favors","racial_resentment","ft_blacks","ft_whites","ft_jews","ft_asians","ft_latinos","ft_aliens","woman","pid","egalitarianism","scope_of_gov","ideology_3pt","economic_evaluation","moral_traditionalism","age","education","married","income","homemaker","biblical_literalism","church_attendance","religion","white","region","weight_variable","Year")]


anes16_subset=anes16[,c("morefamilyties","working_mother_bond","fatherwork_mother_home","traditional_values_index","speacialfavors_women","women_complaints_make_more_problems","modern_sexism_index","modern_sexism_indexv2","percieved_gender_discrimination","percieved_gender_discrimination_rescaled","innocentremarks_as_sexist","appreicate_men_fully","women_seek_controlmen_for_power","tight_leash","hostile_sexism_index","ft_feminists","slavery_hard","blacks_less_than_deserved","blacks_try_harder","blacks_speacial_favors","racial_resentment","ft_blacks","ft_whites","ft_jews","ft_asians","ft_latinos","ft_aliens","woman","pid","egalitarianism","scope_of_gov","ideology_3pt","economic_evaluation","moral_traditionalism","age","education","married","income","homemaker","biblical_literalism","church_attendance","religion","white","region","weight_variable","Year")]

anes20_subset=anes20[,c("morefamilyties","working_mother_bond","fatherwork_mother_home","traditional_values_index","speacialfavors_women","women_complaints_make_more_problems","modern_sexism_index","modern_sexism_indexv2","percieved_gender_discrimination","percieved_gender_discrimination_rescaled","innocentremarks_as_sexist","appreicate_men_fully","women_seek_controlmen_for_power","tight_leash","hostile_sexism_index","ft_feminists","slavery_hard","blacks_less_than_deserved","blacks_try_harder","blacks_speacial_favors","racial_resentment","ft_blacks","ft_whites","ft_jews","ft_asians","ft_latinos","ft_aliens","woman","pid","egalitarianism","scope_of_gov","ideology_3pt","economic_evaluation","moral_traditionalism","age","education","married","income","homemaker","biblical_literalism","church_attendance","religion","white","region","weight_variable","Year")]



anes_combined=rbind(anes04_subset,anes08_subset,anes12_subset,anes16_subset,anes20_subset)

save(anes_combined, file="compiled_data.Rdata")
```



